Skip to content

Commit

Permalink
Fix broken PropertyAccessorDecorator test
Browse files Browse the repository at this point in the history
  • Loading branch information
mxr576 committed Oct 12, 2020
1 parent 52e4713 commit cf38154
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0",
"psr/http-message": "^1.0",
"symfony/options-resolver": "^3.4 || ^4.0",
"symfony/property-access": "^3.4 || ^4.0",
"symfony/property-access": "^3.4.41 || ^4.4.9",
"symfony/property-info": "^3.4 || ^4.0",
"symfony/serializer": "^3.4 || ^4.0"
},
Expand Down
32 changes: 32 additions & 0 deletions tests/PropertyAccess/PhpUnitBcBridgeTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Apigee\Edge\Tests\PropertyAccess;

trait PhpUnitBcBridgeTrait
{
/**
* BC fix for https://github.com/sebastianbergmann/phpunit/commit/d1199cb2e43a934b51521656be9748f63febe18e.
*
* Symfony tests depends on newer version of PHPUnit than this library.
*/
public function expectExceptionMessageMatches(string $regularExpression): void
{
$this->expectedExceptionMessageRegExp = $regularExpression;
}
}
15 changes: 11 additions & 4 deletions tests/PropertyAccess/PropertyAccessorDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@
namespace Apigee\Edge\Tests\PropertyAccess;

use Apigee\Edge\Exception\UnexpectedValueException;
use Apigee\Edge\Exception\UninitializedPropertyException;
use Apigee\Edge\PropertyAccess\PropertyAccessorDecorator;
use Symfony\Component\PropertyAccess\Exception\AccessException;
use Symfony\Component\PropertyAccess\Exception\InvalidArgumentException;
use Symfony\Component\PropertyAccess\PropertyAccessor;
use Symfony\Component\PropertyAccess\Tests\PropertyAccessorTest;

class PropertyAccessorDecoratorTest extends PropertyAccessorTest
{
use PhpUnitBcBridgeTrait;

/**
* @var \Apigee\Edge\PropertyAccess\PropertyAccessorDecorator
*/
Expand Down Expand Up @@ -123,13 +125,15 @@ protected function setUp(): void
/**
* @dataProvider exceptionsToGetOnGetValue
*/
public function testGetValueWithInvalidReturns(string $property, string $expectedException, string $expectedExceptionMessageRegexp): void
public function testGetValueWithInvalidReturns(string $property, string $expectedException, string $expectedExceptionMessageRegexp = null): void
{
try {
$this->propertyAccessor->getValue(static::$testObj, $property);
} catch (\Exception $exception) {
$this->assertInstanceOf($expectedException, $exception);
$this->assertRegExp($expectedExceptionMessageRegexp, $exception->getMessage());
if (null !== $expectedExceptionMessageRegexp) {
$this->assertRegExp($expectedExceptionMessageRegexp, $exception->getMessage());
}
} finally {
if (!isset($exception)) {
$this->fail('An exception should have been thrown.');
Expand Down Expand Up @@ -174,7 +178,10 @@ public function testSetValueOnQueryBuilderParameter(): void
public function exceptionsToGetOnGetValue(): array
{
return [
['shouldBeAStringArray', UninitializedPropertyException::class, '/^Property "shouldBeAStringArray" has not been initialized on instance of class@anonymous.* class. Expected type: "array".$/'],
// It seems the upstream issue has been fixed, throwing an
// unexpected value exception for this case is no longer needed.
// https://github.com/symfony/property-access/commit/e1a6c91c0007e45bc1beba929c76548ca9fe8a85
['shouldBeAStringArray', AccessException::class],
['shouldBeAString', UnexpectedValueException::class, '/Invalid value returned for shouldBeAString property on instance of class@anonymous.* class. Expected type "string", got "stdClass".$/'],
];
}
Expand Down

0 comments on commit cf38154

Please sign in to comment.