Skip to content

Commit

Permalink
Fix PHPUnit deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
malarzm committed Aug 8, 2022
1 parent 6a0ba0d commit 62c2914
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
14 changes: 14 additions & 0 deletions tests/Doctrine/Tests/Common/Proxy/InvokationSpy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php
declare(strict_types=1);

namespace Doctrine\Tests\Common\Proxy;

class InvokationSpy
{
public $invokations = [];

public function __invoke($proxy, $method, $parameters)
{
$this->invokations[] = [$proxy, $method, $parameters];
}
}
27 changes: 13 additions & 14 deletions tests/Doctrine/Tests/Common/Proxy/ProxyLogicTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\Common\Proxy\Proxy;
use Doctrine\Common\Proxy\ProxyGenerator;
use Doctrine\Persistence\Mapping\ClassMetadata;
use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
Expand Down Expand Up @@ -193,13 +192,16 @@ static function () use ($test) {
self::assertSame('publicAssociationValue', $this->lazyObject->publicAssociation);
}

/**
* @requires PHP >= 7.2
*/
public function testNoticeWhenReadingNonExistentPublicProperties()
{
$this->configureInitializerMock(0);

$class = get_class($this->lazyObject);
$this->expectException(Notice::class);
$this->expectExceptionMessage('Undefined property: ' . $class . '::$non_existing_property');
$this->expectNotice();
$this->expectNoticeMessage('Undefined property: ' . $class . '::$non_existing_property');

$this->lazyObject->non_existing_property;
}
Expand Down Expand Up @@ -610,8 +612,7 @@ public function testCallingVariadicMethodCausesLazyLoading()
require_once $proxyGenerator->getProxyFileName($metadata->getName());
}

/** @var callable&MockObject $invocationMock */
$invocationMock = $this->getMockBuilder(stdClass::class)->setMethods(['__invoke'])->getMock();
$invocationMock = new InvokationSpy();

/** @var VariadicTypeHintClass $lazyObject */
$lazyObject = new $proxyClassName(
Expand All @@ -622,19 +623,17 @@ static function () {
}
);

$invocationMock
->expects($this->at(0))
->method('__invoke')
->with($lazyObject, 'addType', [['type1', 'type2']]);
$invocationMock
->expects($this->at(1))
->method('__invoke')
->with($lazyObject, 'addTypeWithMultipleParameters', ['foo', 'bar', ['baz1', 'baz2']]);

$lazyObject->addType('type1', 'type2');
self::assertCount(1, $invocationMock->invokations);
self::assertSame([$lazyObject, 'addType', [['type1', 'type2']]], $invocationMock->invokations[0]);
self::assertSame(['type1', 'type2'], $lazyObject->types);

$lazyObject->addTypeWithMultipleParameters('foo', 'bar', 'baz1', 'baz2');
self::assertCount(2, $invocationMock->invokations);
self::assertSame(
[$lazyObject, 'addTypeWithMultipleParameters', ['foo', 'bar', ['baz1', 'baz2']]],
$invocationMock->invokations[1]
);
self::assertSame('foo', $lazyObject->foo);
self::assertSame('bar', $lazyObject->bar);
self::assertSame(['baz1', 'baz2'], $lazyObject->baz);
Expand Down
27 changes: 13 additions & 14 deletions tests/Doctrine/Tests/Common/Proxy/ProxyLogicTypedPropertiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\Common\Proxy\Proxy;
use Doctrine\Common\Proxy\ProxyGenerator;
use Doctrine\Persistence\Mapping\ClassMetadata;
use PHPUnit\Framework\Error\Notice;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionClass;
Expand Down Expand Up @@ -200,13 +199,16 @@ static function () use ($test) {
self::assertSame('publicAssociationValue', $this->lazyObject->publicAssociation);
}

/**
* @requires PHP >= 7.2
*/
public function testNoticeWhenReadingNonExistentPublicProperties()
{
$this->configureInitializerMock(0);

$class = get_class($this->lazyObject);
$this->expectException(Notice::class);
$this->expectExceptionMessage('Undefined property: ' . $class . '::$non_existing_property');
$this->expectNotice();
$this->expectNoticeMessage('Undefined property: ' . $class . '::$non_existing_property');

$this->lazyObject->non_existing_property;
}
Expand Down Expand Up @@ -613,8 +615,7 @@ public function testCallingVariadicMethodCausesLazyLoading()
require_once $proxyGenerator->getProxyFileName($metadata->getName());
}

/** @var callable&MockObject $invocationMock */
$invocationMock = $this->getMockBuilder(stdClass::class)->setMethods(['__invoke'])->getMock();
$invocationMock = new InvokationSpy();

/** @var VariadicTypeHintClass $lazyObject */
$lazyObject = new $proxyClassName(
Expand All @@ -625,19 +626,17 @@ static function () {
}
);

$invocationMock
->expects($this->at(0))
->method('__invoke')
->with($lazyObject, 'addType', [['type1', 'type2']]);
$invocationMock
->expects($this->at(1))
->method('__invoke')
->with($lazyObject, 'addTypeWithMultipleParameters', ['foo', 'bar', ['baz1', 'baz2']]);

$lazyObject->addType('type1', 'type2');
self::assertCount(1, $invocationMock->invokations);
self::assertSame([$lazyObject, 'addType', [['type1', 'type2']]], $invocationMock->invokations[0]);
self::assertSame(['type1', 'type2'], $lazyObject->types);

$lazyObject->addTypeWithMultipleParameters('foo', 'bar', 'baz1', 'baz2');
self::assertCount(2, $invocationMock->invokations);
self::assertSame(
[$lazyObject, 'addTypeWithMultipleParameters', ['foo', 'bar', ['baz1', 'baz2']]],
$invocationMock->invokations[1]
);
self::assertSame('foo', $lazyObject->foo);
self::assertSame('bar', $lazyObject->bar);
self::assertSame(['baz1', 'baz2'], $lazyObject->baz);
Expand Down

0 comments on commit 62c2914

Please sign in to comment.