1 | <?php |
||
12 | class ResourceHandlerTest extends \PHPUnit_Framework_TestCase |
||
13 | { |
||
14 | /** |
||
15 | * @test |
||
16 | */ |
||
17 | public function initialize() |
||
23 | |||
24 | /** |
||
25 | * @test |
||
26 | * @expectedException \Exception |
||
27 | */ |
||
28 | public function getSingleWrongEntityManager() |
||
40 | |||
41 | /** |
||
42 | * @test |
||
43 | */ |
||
44 | public function getSingle() |
||
65 | |||
66 | /** |
||
67 | * @test |
||
68 | */ |
||
69 | public function getCollection() |
||
90 | |||
91 | /** |
||
92 | * @test |
||
93 | */ |
||
94 | public function postSingle() |
||
|
|||
95 | { |
||
96 | $data = array('name' => 'Random Joe', 'dateOfBirth' => '1970-01-01'); |
||
97 | |||
98 | $product = new Product(); |
||
99 | $product->setName($data['name']); |
||
100 | $product->setDateOfBirth($data['dateOfBirth']); |
||
101 | |||
102 | $entityManager = $this->getMockBuilder('Managlea\Component\EntityManager\DoctrineEntityManager') |
||
103 | ->disableOriginalConstructor() |
||
104 | ->getMock(); |
||
105 | $entityManager->method('create') |
||
106 | ->willReturn($product); |
||
107 | |||
108 | $entityManagerFactory = $this->getMockBuilder('Managlea\Component\EntityManagerFactory') |
||
109 | ->disableOriginalConstructor() |
||
110 | ->getMock(); |
||
111 | $entityManagerFactory->method('create') |
||
112 | ->willReturn($entityManager); |
||
113 | $resourceMapper = new ResourceMapper; |
||
114 | |||
115 | $resourceHandler = ResourceHandler::initialize($entityManagerFactory, $resourceMapper); |
||
116 | |||
117 | $resource = $resourceHandler->postSingle('product', $data); |
||
118 | $this->assertEquals($data['name'], $resource->getName()); |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * @test |
||
123 | */ |
||
124 | public function putSingle() |
||
125 | { |
||
126 | $data = array('name' => 'Random Joe', 'dateOfBirth' => '1970-01-02'); |
||
127 | |||
128 | $product = new Product(); |
||
129 | $product->setName($data['name']); |
||
130 | $product->setDateOfBirth($data['dateOfBirth']); |
||
131 | |||
132 | $entityManager = $this->getMockBuilder('Managlea\Component\EntityManager\DoctrineEntityManager') |
||
133 | ->disableOriginalConstructor() |
||
134 | ->getMock(); |
||
135 | $entityManager->method('update') |
||
136 | ->willReturn($product); |
||
137 | |||
138 | $entityManagerFactory = $this->getMockBuilder('Managlea\Component\EntityManagerFactory') |
||
139 | ->disableOriginalConstructor() |
||
140 | ->getMock(); |
||
141 | $entityManagerFactory->method('create') |
||
142 | ->willReturn($entityManager); |
||
143 | $resourceMapper = new ResourceMapper; |
||
144 | |||
145 | $resourceHandler = ResourceHandler::initialize($entityManagerFactory, $resourceMapper); |
||
146 | |||
147 | $resource = $resourceHandler->putSingle('product', 1, $data); |
||
148 | $this->assertEquals($data['name'], $resource->getName()); |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @test |
||
153 | */ |
||
154 | public function deleteSingle() |
||
174 | } |
||
175 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.