Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
qa: fix test suite to work with PHPUnit 9.5
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Weier O'Phinney <[email protected]>
  • Loading branch information
weierophinney committed Oct 1, 2021
1 parent 55ab194 commit da2d280
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
30 changes: 30 additions & 0 deletions test/DeprecatedAssertionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace LaminasTest\Config;

use PHPUnit\Framework\TestCase;
use ReflectionProperty;

use function sprintf;

trait DeprecatedAssertionTrait
{
/** @param mixed $value */
public static function assertAttributeSame($value, string $property, object $instance, string $message = ''): void
{
$r = new ReflectionProperty($instance, $property);
$r->setAccessible(true);

if ($message === '') {
$message = sprintf(
'Failed asserting property %s::$%s with value %s matches value %s',
get_class($instance),
$property,
var_export($value, true),
var_export($r->getValue($instance), true)
);
}

TestCase::assertSame($value, $r->getValue($instance), $message);
}
}
15 changes: 9 additions & 6 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Laminas\Config\StandaloneReaderPluginManager;
use Laminas\Config\StandaloneWriterPluginManager;
use Laminas\Config\WriterPluginManager;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
use RuntimeException;
Expand Down Expand Up @@ -192,8 +193,9 @@ public function testFactoryCanRegisterCustomReaderInstance()

public function testFactoryCanRegisterCustomReaderPlugin()
{
$services = $this->prophesize(ContainerInterface::class);
$pluginManager = new ReaderPluginManager($services->reveal(), ['services' => [
/** @var ContainerInterface&MockObject $services */
$services = $this->createMock(ContainerInterface::class);
$pluginManager = new ReaderPluginManager($services, ['services' => [
'DummyReader' => new Reader\TestAssets\DummyReader(),
]]);
Factory::setReaderPluginManager($pluginManager);
Expand All @@ -208,13 +210,13 @@ public function testFactoryCanRegisterCustomReaderPlugin()
public function testFactoryToFileInvalidFileExtension()
{
$this->expectException(RuntimeException::class);
$result = Factory::toFile(__DIR__.'/TestAssets/bad.ext', []);
Factory::toFile(__DIR__.'/TestAssets/bad.ext', []);
}

public function testFactoryToFileNoDirInHere()
{
$this->expectException(RuntimeException::class);
$result = Factory::toFile(__DIR__.'/TestAssets/NoDirInHere/nonExisiting/dummy.php', []);
Factory::toFile(__DIR__.'/TestAssets/NoDirInHere/nonExisiting/dummy.php', []);
}

public function testFactoryWriteToFile()
Expand Down Expand Up @@ -263,8 +265,9 @@ public function testFactoryCanRegisterCustomWriterInstance()

public function testFactoryCanRegisterCustomWriterPlugin()
{
$services = $this->prophesize(ContainerInterface::class);
$pluginManager = new WriterPluginManager($services->reveal(), ['services' => [
/** @var ContainerInterface&MockObject $services */
$services = $this->createMock(ContainerInterface::class);
$pluginManager = new WriterPluginManager($services, ['services' => [
'DummyWriter' => new Writer\TestAssets\DummyWriter(),
]]);
Factory::setWriterPluginManager($pluginManager);
Expand Down
3 changes: 3 additions & 0 deletions test/Processor/ConstantTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@

use Laminas\Config\Config;
use Laminas\Config\Processor\Constant as ConstantProcessor;
use LaminasTest\Config\DeprecatedAssertionTrait;
use PHPUnit\Framework\TestCase;

use function define;
use function defined;

class ConstantTest extends TestCase
{
use DeprecatedAssertionTrait;

const CONFIG_TEST = 'config';

public function constantProvider()
Expand Down
3 changes: 3 additions & 0 deletions test/Processor/TokenTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LaminasTest\Config\Processor;

use Laminas\Config\Processor\Token as TokenProcessor;
use LaminasTest\Config\DeprecatedAssertionTrait;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -11,6 +12,8 @@
*/
class TokenTest extends TestCase
{
use DeprecatedAssertionTrait;

public function testKeyProcessingDisabledByDefault()
{
$processor = new TokenProcessor();
Expand Down
22 changes: 2 additions & 20 deletions test/Reader/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

use Laminas\Config\Exception;
use Laminas\Config\Reader\Xml;
use PHPUnit\Framework\Error\Warning;
use ReflectionProperty;
use ValueError;
use XMLReader;

use function class_exists;
use function restore_error_handler;
use function sys_get_temp_dir;

Expand Down Expand Up @@ -41,21 +38,6 @@ protected function getTestAssetPath($name)
return __DIR__ . '/TestAssets/Xml/' . $name . '.xml';
}

/**
* PHPUnit 5.7 does not namespace error classes; retrieve appropriate one
* based on what is available.
*
* @return string
*/
protected function getExpectedWarningClass()
{
if (PHP_MAJOR_VERSION === 8) {
return ValueError::class;
}

return class_exists(Warning::class) ? Warning::class : \PHPUnit_Framework_Error_Warning::class;
}

public function testInvalidXmlFile()
{
$this->reader = new Xml();
Expand Down Expand Up @@ -166,7 +148,7 @@ public function testCloseWhenCallFromFileReaderGetInvalid()

$xmlReader = $this->getInternalXmlReader($configReader);

$this->expectException($this->getExpectedWarningClass());
$this->expectWarning();

// following operation should fail because the internal reader is closed (and expected to be closed)
$xmlReader->setParserProperty(XMLReader::VALIDATE, true);
Expand Down Expand Up @@ -194,7 +176,7 @@ public function testCloseWhenCallFromStringReaderGetInvalid()

$xmlReader = $this->getInternalXmlReader($configReader);

$this->expectException($this->getExpectedWarningClass());
$this->expectWarning();

// following operation should fail because the internal reader is closed (and expected to be closed)
$xmlReader->setParserProperty(XMLReader::VALIDATE, true);
Expand Down

0 comments on commit da2d280

Please sign in to comment.