Skip to content

Commit 3c87ec9

Browse files
committed
remove setting a protected property with a hack in pagination test
1 parent 9091978 commit 3c87ec9

File tree

2 files changed

+5
-32
lines changed

2 files changed

+5
-32
lines changed

tests/Clients/CreditNoteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ public function testDocumentContent(): void
179179

180180
public function testFailedDocumentContent(): void
181181
{
182-
[$api, $stub] = $this->createClientMultiMockObject(
182+
[, $stub] = $this->createClientMultiMockObject(
183183
CreditNote::class,
184184
[
185185
new Response(500),

tests/PaginationClientTest.php

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
use GuzzleHttp\Psr7\Response;
88
use PHPUnit\Framework\MockObject\MockObject;
9-
use ReflectionClass;
10-
use ReflectionException;
119
use Sysix\LexOffice\Api;
1210
use Sysix\LexOffice\PaginationClient;
1311

@@ -16,44 +14,19 @@ class PaginationClientTest extends TestClient
1614
/**
1715
* @param Response[] $responses
1816
*
19-
* @throws ReflectionException
20-
*
21-
* @return array{0: Api&MockObject, 1: PaginationClient&MockObject}
17+
* @return array{0: Api&MockObject, 1: PaginationClient}
2218
*/
2319
public function createPaginationClientMockObject(array $responses)
2420
{
2521
$api = $this->createApiMultiMockObject($responses);
2622

27-
$stub = $this
28-
->getMockBuilder(PaginationClient::class)
29-
->onlyMethods([])
30-
->setConstructorArgs([$api])
31-
->getMock();
32-
33-
$this->setProtectedProperty($stub, 'resource', 'resource');
23+
$stub = new class($api) extends PaginationClient {
24+
protected string $resource = 'resource';
25+
};
3426

3527
return [$api, $stub];
3628
}
3729

38-
/**
39-
* Sets a protected property on a given object via reflection.
40-
*
41-
* @param object $object - instance in which protected value is being modified
42-
* @param string $property - property on instance being modified
43-
* @param mixed $value - new value of the property being modified
44-
*
45-
* @throws ReflectionException
46-
*
47-
* @see https://stackoverflow.com/a/37667018/7387397
48-
*/
49-
public function setProtectedProperty(object $object, string $property, $value): void
50-
{
51-
$reflection = new ReflectionClass($object);
52-
$reflection_property = $reflection->getProperty($property);
53-
$reflection_property->setAccessible(true);
54-
$reflection_property->setValue($object, $value);
55-
}
56-
5730
public function testGetAllSingle(): void
5831
{
5932
$this->expectDeprecationV1Warning('getAll');

0 commit comments

Comments
 (0)