Skip to content

Commit

Permalink
Upgrade to PHPUnit 8.5 (theorchard#103)
Browse files Browse the repository at this point in the history
* Update PHPUnit to 8.5

This is required in order to run tests with Monolog 2. Otherwise this error occurs:

PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

..................PHP Fatal error:  Declaration of Mock_TestHandler_bc3472b7::setFormatter(Monolog\Formatter\FormatterInterface $formatter) must be compatible with Monolog\Handler\AbstractProcessingHandler::setFormatter(Monolog\Formatter\FormatterInterface $formatter): Monolog\Handler\HandlerInterface in /home/danilo/monolog-cascade/vendor/phpunit/phpunit-mock-objects/src/Framework/MockObject/Generator.php(290) : eval()'d code on line 11

* Fix TestCase inheritance

Fixes this type of error:

`Fatal error: Uncaught Error: Class 'PHPUnit_Framework_TestCase' not found in /home/danilo/monolog-cascade/tests/Config/Loader/FileLoader/FileLoaderAbstractTest.php:26`

* Use TestCase::getMockBuilder instead of TestCase::getMock

Fixes this type of error:

`Error: Call to undefined method Cascade\Tests\Config\Loader\FileLoader\FileLoaderAbstractTest::getMock()`

* Fix HandlerLoaderTest::testHandlerForProcessor

ProcessableHandlerInterface::pushProcessor expects the $callback argument to be a callable. Fixes the following error:

`Cascade\Tests\Config\Loader\ClassLoader\HandlerLoaderTest::testHandlerForProcessor
 TypeError: Argument 1 passed to Mock_TestHandler_aac1a74a::pushProcessor() must be callable, string given, called in /home/danilo/monolog-cascade/src/Config/Loader/ClassLoader/HandlerLoader.php on line 187`

* Remove usages of @ExpectedException annotations

Fixes this warning:

`The @ExpectedException, @expectedExceptionCode, @expectedExceptionMessage, and @expectedExceptionMessageRegExp annotations are deprecated. They will be removed in PHPUnit 9. Refactor your test to use expectException(), expectExceptionCode(), expectExceptionMessage(), or expectExceptionMessageMatches() instead.`

Co-authored-by: Danilo Azevedo <[email protected]>
  • Loading branch information
hertz1 and Danilo Azevedo authored Jan 25, 2022
1 parent 38e1b56 commit 9d3a197
Show file tree
Hide file tree
Showing 17 changed files with 106 additions and 85 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
],
"homepage": "https://github.com/theorchard/monolog-cascade",
"require": {
"php": "^5.3.9 || ^7.0",
"php": ">=7.2",
"symfony/config": "^2.7 || ^3.0 || ^4.0 || ^5.0",
"symfony/options-resolver": "^2.7 || ^3.0 || ^4.0 || ^5.0",
"symfony/serializer": "^2.7 || ^3.0 || ^4.0 || ^5.0",
Expand All @@ -32,8 +32,8 @@
},
"require-dev": {
"mikey179/vfsstream": "^1.6",
"phpunit/phpcov": "^2.0",
"phpunit/phpunit": "^4.8",
"phpunit/phpcov": "^6.0",
"phpunit/phpunit": "^8.5",
"php-coveralls/php-coveralls": "^1.0",
"squizlabs/php_codesniffer": "^2.5"
},
Expand Down
10 changes: 5 additions & 5 deletions tests/CascadeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
use Monolog\Registry;

use Cascade\Cascade;
use PHPUnit\Framework\TestCase;

/**
* Class CascadeTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class CascadeTest extends \PHPUnit_Framework_TestCase
class CascadeTest extends TestCase
{
public function teardown()
public function teardown(): void
{
Registry::clear();
parent::teardown();
Expand All @@ -47,11 +48,10 @@ public function testRegistry()
$this->assertSame($logger, $logger2);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testRegistryWithInvalidName()
{
$this->expectException(\InvalidArgumentException::class);

Cascade::getLogger(null);
}

Expand Down
7 changes: 4 additions & 3 deletions tests/Config/ConfigLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,28 @@

use Cascade\Config\ConfigLoader;
use Cascade\Tests\Fixtures;
use PHPUnit\Framework\TestCase;

/**
* Class ConfigLoaderTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class ConfigLoaderTest extends \PHPUnit_Framework_TestCase
class ConfigLoaderTest extends TestCase
{
/**
* Loader to test against
* @var ConfigLoader
*/
protected $loader = null;

public function setUp()
public function setUp(): void
{
parent::setup();
$this->loader = new ConfigLoader();
}

public function tearDown()
public function tearDown(): void
{
$this->loader = null;
parent::tearDown();
Expand Down
7 changes: 4 additions & 3 deletions tests/Config/Loader/ClassLoader/FormatterLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@
namespace Cascade\Tests\Config\Loader\ClassLoader;

use Cascade\Config\Loader\ClassLoader\FormatterLoader;
use PHPUnit\Framework\TestCase;

/**
* Class FormatterLoaderTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class FormatterLoaderTest extends \PHPUnit_Framework_TestCase
class FormatterLoaderTest extends TestCase
{
/**
* Set up function
*/
public function setUp()
public function setUp(): void
{
parent::setUp();
new FormatterLoader(array());
Expand All @@ -31,7 +32,7 @@ public function setUp()
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
FormatterLoader::$extraOptionHandlers = array();
parent::tearDown();
Expand Down
33 changes: 18 additions & 15 deletions tests/Config/Loader/ClassLoader/HandlerLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
use Monolog\Formatter\LineFormatter;

use Cascade\Config\Loader\ClassLoader\HandlerLoader;
use PHPUnit\Framework\TestCase;

/**
* Class HandlerLoaderTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class HandlerLoaderTest extends \PHPUnit_Framework_TestCase
class HandlerLoaderTest extends TestCase
{
public function testHandlerLoader()
{
Expand Down Expand Up @@ -53,11 +54,10 @@ public function testHandlerLoaderWithNoOptions()
$this->assertEquals($original, $options);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testHandlerLoaderWithInvalidFormatter()
{
$this->expectException(\InvalidArgumentException::class);

$options = array(
'formatter' => 'test_formatter'
);
Expand All @@ -66,11 +66,10 @@ public function testHandlerLoaderWithInvalidFormatter()
$loader = new HandlerLoader($options, $formatters);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testHandlerLoaderWithInvalidProcessor()
{
$this->expectException(\InvalidArgumentException::class);

$dummyClosure = function () {
// Empty function
};
Expand All @@ -83,11 +82,10 @@ public function testHandlerLoaderWithInvalidProcessor()
$loader = new HandlerLoader($options, $formatters, $processors);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testHandlerLoaderWithInvalidHandler()
{
$this->expectException(\InvalidArgumentException::class);

$dummyClosure = function () {
// Empty function
};
Expand All @@ -101,11 +99,10 @@ public function testHandlerLoaderWithInvalidHandler()
$loader = new HandlerLoader($options, $formatters, $processors, $handlers);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testHandlerLoaderWithInvalidHandlers()
{
$this->expectException(\InvalidArgumentException::class);

$dummyClosure = function () {
// Empty function
};
Expand Down Expand Up @@ -244,8 +241,14 @@ public function testHandlerForProcessor()
{
$options = array();

$mockProcessor1 = '123';
$mockProcessor2 = '456';
$mockProcessor1 = function($record) {
$record['extra']['dummy'] = 'Hello world 1!';
return $record;
};
$mockProcessor2 = function($record) {
$record['extra']['dummy'] = 'Hello world 1!';
return $record;
};
$processorsArray = array($mockProcessor1, $mockProcessor2);

// Setup mock and expectations
Expand Down
15 changes: 7 additions & 8 deletions tests/Config/Loader/ClassLoader/LoggerLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
use Monolog\Registry;

use Cascade\Config\Loader\ClassLoader\LoggerLoader;
use PHPUnit\Framework\TestCase;

/**
* Class LoggerLoaderTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class LoggerLoaderTest extends \PHPUnit_Framework_TestCase
class LoggerLoaderTest extends TestCase
{
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
parent::tearDown();
Registry::clear();
Expand Down Expand Up @@ -56,11 +57,10 @@ public function testResolveHandlers()
);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testResolveHandlersWithMismatch()
{
$this->expectException(\InvalidArgumentException::class);

$options = array(
'handlers' => array('unexisting_handler', 'test_handler_2')
);
Expand Down Expand Up @@ -95,11 +95,10 @@ public function testResolveProcessors()
);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testResolveProcessorsWithMismatch()
{
$this->expectException(\InvalidArgumentException::class);

$dummyClosure = function () {
// Empty function
};
Expand Down
3 changes: 2 additions & 1 deletion tests/Config/Loader/ClassLoader/ProcessorLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
use Monolog\Processor\WebProcessor;

use Cascade\Config\Loader\ClassLoader\ProcessorLoader;
use PHPUnit\Framework\TestCase;

/**
* Class ProcessorLoaderTest
*
* @author Kate Burdon <[email protected]>
*/
class ProcessorLoaderTest extends \PHPUnit_Framework_TestCase
class ProcessorLoaderTest extends TestCase
{
public function testProcessorLoader()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,17 @@
use Cascade\Util;
use Cascade\Config\Loader\ClassLoader\Resolver\ConstructorResolver;

use PHPUnit\Framework\TestCase;
use Symfony;
use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;

/**
* Class ConstructorResolverTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class ConstructorResolverTest extends \PHPUnit_Framework_TestCase
class ConstructorResolverTest extends TestCase
{
/**
* Reflection class for which you want to resolve extra options
Expand All @@ -37,7 +40,7 @@ class ConstructorResolverTest extends \PHPUnit_Framework_TestCase
/**
* Set up function
*/
public function setUp()
public function setUp(): void
{
$this->class = 'Cascade\Tests\Fixtures\SampleClass';
$this->resolver = new ConstructorResolver(new \ReflectionClass($this->class));
Expand All @@ -47,7 +50,7 @@ public function setUp()
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
$this->resolver = null;
$this->class = null;
Expand Down Expand Up @@ -183,10 +186,11 @@ public function missingOptionsProvider()
*
* @param array $incompleteOptions Array of invalid options
* @dataProvider missingOptionsProvider
* @expectedException Symfony\Component\OptionsResolver\Exception\MissingOptionsException
*/
public function testResolveWithMissingOptions(array $incompleteOptions)
{
$this->expectException(MissingOptionsException::class);

$this->resolver->resolve($incompleteOptions);
}

Expand Down Expand Up @@ -222,10 +226,11 @@ public function invalidOptionsProvider()
*
* @param array $invalidOptions Array of invalid options
* @dataProvider invalidOptionsProvider
* @expectedException Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testResolveWithInvalidOptions($invalidOptions)
{
$this->expectException(UndefinedOptionsException::class);

$this->resolver->resolve($invalidOptions);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@

use Cascade\Config\Loader\ClassLoader\Resolver\ExtraOptionsResolver;

use PHPUnit\Framework\TestCase;
use Symfony;
use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;

/**
* Class ExtraOptionsResolverTest
*
* @author Raphael Antonmattei <[email protected]>
*/
class ExtraOptionsResolverTest extends \PHPUnit_Framework_TestCase
class ExtraOptionsResolverTest extends TestCase
{
/**
* Reflection class for which you want to resolve extra options
Expand All @@ -36,7 +38,7 @@ class ExtraOptionsResolverTest extends \PHPUnit_Framework_TestCase
/**
* Set up function
*/
public function setUp()
public function setUp(): void
{
$this->class = 'Cascade\Tests\Fixtures\SampleClass';
$this->params = array('optionalA', 'optionalB');
Expand All @@ -50,7 +52,7 @@ public function setUp()
/**
* Tear down function
*/
public function tearDown()
public function tearDown(): void
{
$this->resolver = null;
$this->class = null;
Expand Down Expand Up @@ -168,10 +170,11 @@ public function invalidOptionsProvider()
*
* @param array $invalidOptions Array of invalid options
* @dataProvider invalidOptionsProvider
* @expectedException Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException
*/
public function testResolveWithInvalidOptions($invalidOptions)
{
$this->expectException(UndefinedOptionsException::class);

$this->resolver->resolve($invalidOptions);
}
}
Loading

0 comments on commit 9d3a197

Please sign in to comment.