@@ 114-137 (lines=24) @@ | ||
111 | $this->assertSame($expectedChoices, $choices); |
|
112 | } |
|
113 | ||
114 | public function testBuildingChoicesFromRepositoryMethodWhenMethodDoesNotExist() |
|
115 | { |
|
116 | $methodName = 'a_method'; |
|
117 | $repositoryName = 'a_test_repository'; |
|
118 | ||
119 | $repositoryMock = $this->prepareRepositoryMock([$methodName]); |
|
120 | $repositoryMock->expects($this->never()) |
|
121 | ->method($methodName); |
|
122 | ||
123 | $emMock = $this->prepareEntityManagerMock(); |
|
124 | $emMock->expects($this->once()) |
|
125 | ->method('getRepository') |
|
126 | ->with($this->equalTo($repositoryName)) |
|
127 | ->willReturn($repositoryMock); |
|
128 | ||
129 | $builder = new ChoicesBuilder($emMock); |
|
130 | ||
131 | $this->expectException(\Exception::class); |
|
132 | $this->expectExceptionMessage("Specified repository does not have 'other_method' method"); |
|
133 | $builder->build( |
|
134 | [ |
|
135 | 'repository' => $repositoryName, |
|
136 | 'method' => 'other_method', |
|
137 | ] |
|
138 | ); |
|
139 | } |
|
140 | ||
@@ 141-165 (lines=25) @@ | ||
138 | ); |
|
139 | } |
|
140 | ||
141 | public function testBuildingChoicesFromRepositoryMethodWhenMethodDoesNotReturnAnArray() |
|
142 | { |
|
143 | $methodName = 'a_method'; |
|
144 | $repositoryName = 'a_test_repository'; |
|
145 | ||
146 | $repositoryMock = $this->prepareRepositoryMock([$methodName]); |
|
147 | $repositoryMock->expects($this->once()) |
|
148 | ->method($methodName) |
|
149 | ->willReturn('not an array'); |
|
150 | ||
151 | $emMock = $this->prepareEntityManagerMock(); |
|
152 | $emMock->expects($this->once()) |
|
153 | ->method('getRepository') |
|
154 | ->with($this->equalTo($repositoryName)) |
|
155 | ->willReturn($repositoryMock); |
|
156 | ||
157 | $builder = new ChoicesBuilder($emMock); |
|
158 | ||
159 | $this->expectException(\Exception::class); |
|
160 | $this->expectExceptionMessage("Repository method $methodName must return an array of choices"); |
|
161 | $builder->build( |
|
162 | [ |
|
163 | 'repository' => $repositoryName, |
|
164 | 'method' => $methodName, |
|
165 | ] |
|
166 | ); |
|
167 | } |
|
168 |