1 | <?php |
||
22 | abstract class UnitTestCase extends TestCase |
||
23 | { |
||
24 | use ReflectionMethods; |
||
25 | use OnlyTestLogging; |
||
26 | |||
27 | //<editor-fold desc="Protected Methods"> |
||
28 | |||
29 | /** |
||
30 | * Creates a stub with a given set of stubbed methods, which will return the given results |
||
31 | * @param string $class the class name |
||
32 | * @param array $methodResults a dictionary mapping method names to results of this methods |
||
33 | * @return MockObject the configured stub |
||
34 | */ |
||
35 | protected function createStub(string $class, array $methodResults): MockObject |
||
43 | |||
44 | /** |
||
45 | * Creates an empty mock with a getId method |
||
46 | * @param string $class the class to mock |
||
47 | * @param string $entityId the id to assign |
||
48 | * @param string $getterMethod the name of the getter method |
||
49 | * @return \PHPUnit\Framework\MockObject\MockObject the mocked instance |
||
50 | */ |
||
51 | protected function createStubWithId(string $class, $entityId = "entity-id", $getterMethod = 'getId') |
||
55 | |||
56 | /** |
||
57 | * Gets a mock for an entity manager which creates a query builder which will return a query which will return the |
||
58 | * given result. |
||
59 | * @param array $result the result array the query should return |
||
60 | * @param string|null $expectedQuery the expected query if set |
||
61 | * @param string[] $otherMockedMethods list of other methods to mock |
||
62 | * @return MockObject the mocked entity manager |
||
63 | */ |
||
64 | protected function getEntityManagerMockForQuery(array $result, ?string $expectedQuery = null, |
||
91 | |||
92 | /** @noinspection PhpDocMissingThrowsInspection */ |
||
93 | /** |
||
94 | * Gets a mock class (with full implementation). The given arguments are used for the arguments for the constructor. |
||
95 | * If too less arguments are given mocks are created for the rest of the constructor arguments. |
||
96 | * @param string $className the class to mock |
||
97 | * @param array $arguments the arguments to use for the constructor |
||
98 | * @param string[] $mockedMethods the methods to mock in the class |
||
99 | * @return MockObject the mocked object |
||
100 | */ |
||
101 | protected final function getMockWithMockedArguments(string $className, array $arguments = [], |
||
113 | |||
114 | /** @noinspection PhpDocMissingThrowsInspection */ |
||
115 | /** |
||
116 | * Gets a new instance of the given class. The given arguments are used for the arguments for the constructor. |
||
117 | * If too less arguments are given mocks are created for the rest of the constructor arguments. |
||
118 | * @param string $className the class for which to create an instance |
||
119 | * @param array $arguments the arguments to use for the constructor |
||
120 | * @return mixed an instance of the given class |
||
121 | */ |
||
122 | protected final function getObjectWithMockedArguments($className, array $arguments = []) |
||
133 | |||
134 | public function tearDown() |
||
138 | //</editor-fold desc="Protected Methods"> |
||
139 | } |