Skip to content

Commit

Permalink
Merge pull request LM-Commons#45 from visto9259/1.4.x
Browse files Browse the repository at this point in the history
Upgraded to Phpunit 11 for PHP >=8.2
  • Loading branch information
visto9259 authored Aug 14, 2024
2 parents 3479aea + 62d5982 commit be15aae
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"laminas/laminas-modulemanager": "^2.7.2",
"laminas/laminas-serializer": "^2.8",
"laminas/laminas-view": "^2.8.1",
"phpunit/phpunit": "^9.5.0",
"phpunit/phpunit": "^10.5 || ^11.0",
"php-coveralls/php-coveralls": "^2.1",
"squizlabs/php_codesniffer": "^3.4"
},
Expand Down
19 changes: 9 additions & 10 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="./tests/Bootstrap.php" colors="true"
convertErrorsToExceptions="true" convertNoticesToExceptions="true"
convertWarningsToExceptions="true" verbose="true" stopOnFailure="false"
processIsolation="false" backupGlobals="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
bootstrap="./tests/Bootstrap.php"
colors="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache">
<testsuite name="LmcCors tests">
<directory>./tests</directory>
</testsuite>
<source>
<include>
<directory>./src</directory>
</include>
</source>
</phpunit>
3 changes: 2 additions & 1 deletion tests/Factory/CorsOptionsFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace LmcCorsTest\Factory;

use LmcCors\Options\CorsOptions;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use LmcCorsTest\Util\ServiceManagerFactory;
use Psr\Container\ContainerExceptionInterface;
Expand All @@ -29,9 +30,9 @@
*
* @author Michaël Gallego <[email protected]>
*
* @covers \LmcCors\Factory\CorsOptionsFactory
* @group Coverage
*/
#[CoversClass('\LmcCors\Factory\CorsOptionsFactory')]
class CorsOptionsFactoryTest extends TestCase
{
/**
Expand Down
3 changes: 2 additions & 1 deletion tests/Factory/CorsRequestListenerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace LmcCorsTest\Factory;

use LmcCors\Mvc\CorsRequestListener;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use LmcCorsTest\Util\ServiceManagerFactory;

Expand All @@ -27,9 +28,9 @@
*
* @author Michaël Gallego <[email protected]>
*
* @covers \LmcCors\Factory\CorsRequestListenerFactory
* @group Coverage
*/
#[CoversClass('\LmcCors\Factory\CorsRequestListenerFactory')]
class CorsRequestListenerFactoryTest extends TestCase
{
public function testCanCreateCorsRequestListener()
Expand Down
3 changes: 2 additions & 1 deletion tests/Factory/CorsServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
namespace LmcCorsTest\Factory;

use LmcCors\Service\CorsService;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase as TestCase;
use LmcCorsTest\Util\ServiceManagerFactory;

Expand All @@ -27,9 +28,9 @@
*
* @author Michaël Gallego <[email protected]>
*
* @covers \LmcCors\Factory\CorsServiceFactory
* @group Coverage
*/
#[CoversClass('\LmcCors\Factory\CorsServiceFactory')]
class CorsServiceFactoryTest extends TestCase
{
public function testCanCreateCorsService()
Expand Down
16 changes: 6 additions & 10 deletions tests/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace LmcCorsTest;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use LmcCors\Module;

Expand All @@ -29,11 +30,9 @@
*
* @group Coverage
*/
#[CoversClass('\LmcCors\Module')]
class ModuleTest extends TestCase
{
/**
* @covers \LmcCors\Module::getConfig
*/
public function testGetConfig()
{
$module = new Module();
Expand All @@ -42,9 +41,6 @@ public function testGetConfig()
$this->assertSame($module->getConfig(), unserialize(serialize($module->getConfig())), 'Config is serializable');
}

/**
* @covers \LmcCors\Module::onBootstrap
*/
public function testAssertListenerIsCorrectlyRegistered()
{
$module = new Module();
Expand All @@ -58,14 +54,14 @@ public function testAssertListenerIsCorrectlyRegistered()
->disableOriginalConstructor()
->getMock();

$mvcEvent->expects($this->any())->method('getTarget')->will($this->returnValue($application));
$application->expects($this->any())->method('getEventManager')->will($this->returnValue($eventManager));
$application->expects($this->any())->method('getServiceManager')->will($this->returnValue($serviceManager));
$mvcEvent->expects($this->any())->method('getTarget')->willReturn($application);
$application->expects($this->any())->method('getEventManager')->willReturn($eventManager);
$application->expects($this->any())->method('getServiceManager')->willReturn($serviceManager);
$serviceManager
->expects($this->any())
->method('get')
->with('LmcCors\Mvc\CorsRequestListener')
->will($this->returnValue($corsListener));
->willReturn($corsListener);

$corsListener->expects($this->once())->method('attach')->with($eventManager);

Expand Down
10 changes: 6 additions & 4 deletions tests/Mvc/CorsRequestListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace LmcCorsTest\Mvc;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Laminas\EventManager\EventManager;
use Laminas\Http\Request as HttpRequest;
Expand All @@ -34,9 +35,9 @@
*
* @author Michaël Gallego <[email protected]>
*
* @covers \LmcCors\Mvc\CorsRequestListener
* @group Coverage
*/
#[CoversClass('\LmcCors\Mvc\CorsRequestListener')]
class CorsRequestListenerTest extends TestCase
{

Expand Down Expand Up @@ -67,13 +68,14 @@ public function testAttach()
$eventManager = $this->getMockBuilder('Laminas\EventManager\EventManagerInterface')->getMock();

$matcher = $this->exactly(2);

$eventManager
->expects($matcher)
->method('attach')
->willReturnCallback(function (string $event, callable $callback, int $priority) use ($matcher) {
match ($matcher->getInvocationCount()) {
1 => $this->assertEquals(MvcEvent::EVENT_ROUTE, $event),
2 => $this->assertEquals(MvcEvent::EVENT_FINISH, $event),
match ($event) {
MvcEvent::EVENT_ROUTE => '',
MvcEvent::EVENT_FINISH => '',
};
});
$this->corsListener->attach($eventManager);
Expand Down
3 changes: 2 additions & 1 deletion tests/Options/CorsOptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace LmcCorsTest\Options;

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use LmcCors\Options\CorsOptions;

Expand All @@ -26,9 +27,9 @@
*
* @author Michaël Gallego <[email protected]>
*
* @covers \LmcCors\Options\CorsOptions
* @group Coverage
*/
#[CoversClass('\LmcCors\Options\CorsOptions')]
class CorsOptionsTest extends TestCase
{
public function testCorsOptionsAreSecuredByDefault()
Expand Down
3 changes: 2 additions & 1 deletion tests/Service/CorsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

use LmcCors\Exception\DisallowedOriginException;
use LmcCors\Exception\InvalidOriginException;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use Laminas\Http\Response as HttpResponse;
use Laminas\Http\Request as HttpRequest;
Expand All @@ -33,9 +34,9 @@
*
* @author Florent Blaison <[email protected]>
*
* @covers \LmcCors\Service\CorsService
* @group Coverage
*/
#[CoversClass('\LmcCors\Service\CorsService')]
class CorsServiceTest extends TestCase
{
/**
Expand Down

0 comments on commit be15aae

Please sign in to comment.