Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit4db3dd9

Browse files
author
Dominik Liebler
committed
Merge pull requestDesignPatternsPHP#111 from jcherqui/master
Validation PSR2
2 parentsfc55b9b +d5b96d1 commit4db3dd9

File tree

7 files changed

+108
-45
lines changed

7 files changed

+108
-45
lines changed

‎Creational/Pool/Tests/PoolTest.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,8 @@
44

55
useDesignPatterns\Creational\Pool\Pool;
66

7-
class TestWorker
8-
{
9-
public$id =1;
10-
}
11-
127
class PoolTestextends \PHPUnit_Framework_TestCase
138
{
14-
159
publicfunctiontestPool()
1610
{
1711
$pool =newPool('DesignPatterns\Creational\Pool\Tests\TestWorker');

‎Creational/Pool/Tests/TestWorker.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespaceDesignPatterns\Creational\Pool\Tests;
4+
5+
class TestWorker
6+
{
7+
public$id =1;
8+
}

‎More/Repository/MemoryStorage.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function retrieve($id)
4040
*/
4141
publicfunctiondelete($id)
4242
{
43-
if(!isset($this->data[$id])){
43+
if(!isset($this->data[$id])){
4444
returnfalse;
4545
}
4646

@@ -49,6 +49,4 @@ public function delete($id)
4949

5050
returntrue;
5151
}
52-
5352
}
54-

‎More/Repository/Post.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespaceDesignPatterns\Repository;
4+
45
/**
56
* Post represents entity for some post that user left on the site
67
*
@@ -34,9 +35,6 @@ class Post
3435
*/
3536
private$created;
3637

37-
38-
39-
4038
/**
4139
* @param int $id
4240
*/
@@ -116,7 +114,4 @@ public function getTitle()
116114
{
117115
return$this->title;
118116
}
119-
120-
121-
122-
}
117+
}

‎More/Repository/PostRepository.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
/**
66
* Repository for class Post
77
* This class is between Entity layer(class Post) and access object layer(interface Storage)
8-
* Repository encapsulates the set of objects persisted in a data store and the operations performed over them, providing a more object-oriented view of the persistence layer
9-
* Repository also supports the objective of achieving a clean separation and one-way dependency between the domain and data mapping layers
8+
*
9+
* Repository encapsulates the set of objects persisted in a data store and the operations performed over them
10+
* providing a more object-oriented view of the persistence layer
11+
*
12+
* Repository also supports the objective of achieving a clean separation and one-way dependency
13+
* between the domain and data mapping layers
1014
*
1115
* Class PostRepository
1216
* @package DesignPatterns\Repository
@@ -29,7 +33,7 @@ public function __construct(Storage $persistence)
2933
publicfunctiongetById($id)
3034
{
3135
$arrayData =$this->persistence->retrieve($id);
32-
if(is_null($arrayData)){
36+
if(is_null($arrayData)){
3337
returnnull;
3438
}
3539

@@ -72,4 +76,4 @@ public function delete(Post $post)
7276
{
7377
return$this->persistence->delete($post->getId());
7478
}
75-
}
79+
}

‎More/Repository/Storage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ public function retrieve($id);
3838
* @return bool
3939
*/
4040
publicfunctiondelete($id);
41-
}
41+
}

‎More/ServiceLocator/Tests/ServiceLocatorTest.php

Lines changed: 88 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,15 @@ public function setUp()
3333

3434
publicfunctiontestHasServices()
3535
{
36-
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface',$this->logService);
37-
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',$this->databaseService);
36+
$this->serviceLocator->add(
37+
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
38+
$this->logService
39+
);
40+
41+
$this->serviceLocator->add(
42+
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
43+
$this->databaseService
44+
);
3845

3946
$this->assertTrue($this->serviceLocator->has('DesignPatterns\More\ServiceLocator\LogServiceInterface'));
4047
$this->assertTrue($this->serviceLocator->has('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface'));
@@ -44,35 +51,92 @@ public function testHasServices()
4451

4552
publicfunctiontestServicesWithObject()
4653
{
47-
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface',$this->logService);
48-
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',$this->databaseService);
49-
50-
$this->assertSame($this->logService,$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface'));
51-
$this->assertSame($this->databaseService,$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface'));
54+
$this->serviceLocator->add(
55+
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
56+
$this->logService
57+
);
58+
59+
$this->serviceLocator->add(
60+
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
61+
$this->databaseService
62+
);
63+
64+
$this->assertSame(
65+
$this->logService,
66+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')
67+
);
68+
69+
$this->assertSame(
70+
$this->databaseService,
71+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')
72+
);
5273
}
5374

5475
publicfunctiontestServicesWithClass()
5576
{
56-
$this->serviceLocator
57-
->add('DesignPatterns\More\ServiceLocator\LogServiceInterface',get_class($this->logService));
58-
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',get_class($this->databaseService));
59-
60-
$this->assertNotSame($this->logService,$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface'));
61-
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\LogServiceInterface',$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface'));
62-
63-
$this->assertNotSame($this->databaseService,$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface'));
64-
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface'));
77+
$this->serviceLocator->add(
78+
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
79+
get_class($this->logService)
80+
);
81+
82+
$this->serviceLocator->add(
83+
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
84+
get_class($this->databaseService)
85+
);
86+
87+
$this->assertNotSame(
88+
$this->logService,
89+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')
90+
);
91+
92+
$this->assertInstanceOf(
93+
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
94+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')
95+
);
96+
97+
$this->assertNotSame(
98+
$this->databaseService,
99+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')
100+
);
101+
102+
$this->assertInstanceOf(
103+
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
104+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')
105+
);
65106
}
66107

67108
publicfunctiontestServicesNotShared()
68109
{
69-
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\LogServiceInterface',$this->logService,false);
70-
$this->serviceLocator->add('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',$this->databaseService,false);
71-
72-
$this->assertNotSame($this->logService,$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface'));
73-
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\LogServiceInterface',$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface'));
74-
75-
$this->assertNotSame($this->databaseService,$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface'));
76-
$this->assertInstanceOf('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface'));
110+
$this->serviceLocator->add(
111+
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
112+
$this->logService,
113+
false
114+
);
115+
116+
$this->serviceLocator->add(
117+
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
118+
$this->databaseService,
119+
false
120+
);
121+
122+
$this->assertNotSame(
123+
$this->logService,
124+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')
125+
);
126+
127+
$this->assertInstanceOf(
128+
'DesignPatterns\More\ServiceLocator\LogServiceInterface',
129+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\LogServiceInterface')
130+
);
131+
132+
$this->assertNotSame(
133+
$this->databaseService,
134+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')
135+
);
136+
137+
$this->assertInstanceOf(
138+
'DesignPatterns\More\ServiceLocator\DatabaseServiceInterface',
139+
$this->serviceLocator->get('DesignPatterns\More\ServiceLocator\DatabaseServiceInterface')
140+
);
77141
}
78142
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp