Skip to content

Commit

Permalink
Migrate to PHP 8.2
Browse files Browse the repository at this point in the history
Migrate to PHPUnit 11
Migrate to usage trait in trait (to simplify usage)
  • Loading branch information
AntonShevchuk committed Sep 10, 2024
1 parent 35c5b66 commit 9574043
Show file tree
Hide file tree
Showing 20 changed files with 224 additions and 69 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
build:
environment:
php: 8.1
php: 8.2
nodes:
analysis:
tests:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"description": "Container package",
"type": "library",
"require": {
"php": ">=8.1"
"php": ">=8.2"
},
"require-dev": {
"phpunit/phpunit": "~10.4"
"phpunit/phpunit": "~11.3"
},
"autoload": {
"psr-4": {
Expand Down
7 changes: 2 additions & 5 deletions src/Container/ArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,11 @@
* @package Bluz\Common
* @author Anton Shevchuk
* @see ArrayAccess
*
* @method void doSetContainer(string $key, mixed $value)
* @method mixed doGetContainer(string $key)
* @method bool doContainsContainer(string $key)
* @method void doDeleteContainer(string $key)
*/
trait ArrayAccess
{
use Container;

/**
* Offset to set
*
Expand Down
4 changes: 2 additions & 2 deletions src/Container/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
namespace Bluz\Container;

/**
* Container of data for object
* Container of data for an object
*
* @package Bluz\Common
* @author Anton Shevchuk
Expand Down Expand Up @@ -102,7 +102,7 @@ public function toArray(): array
}

/**
* Reset container array
* Reset the container array
*
* @return void
*/
Expand Down
4 changes: 2 additions & 2 deletions src/Container/JsonSerialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
* @package Bluz\Common
* @author Anton Shevchuk
* @see JsonSerializable
*
* @method array toArray()
*/
trait JsonSerialize
{
use Container;

/**
* Specify data which should be serialized to JSON
*
Expand Down
7 changes: 2 additions & 5 deletions src/Container/MagicAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
*
* @package Bluz\Common
* @author Anton Shevchuk
*
* @method void doSetContainer(string $key, mixed $value)
* @method mixed doGetContainer(string $key)
* @method bool doContainsContainer(string $key)
* @method void doDeleteContainer(string $key)
*/
trait MagicAccess
{
use Container;

/**
* Magic alias for set() regular method
*
Expand Down
7 changes: 2 additions & 5 deletions src/Container/RegularAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,11 @@
*
* @package Bluz\Common
* @author Anton Shevchuk
*
* @method void doSetContainer(string $key, mixed $value)
* @method mixed doGetContainer(string $key)
* @method bool doContainsContainer(string $key)
* @method void doDeleteContainer(string $key)
*/
trait RegularAccess
{
use Container;

/**
* Set key/value pair
*
Expand Down
3 changes: 1 addition & 2 deletions tests/Container/ArrayContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@

use Bluz\Tests\Container\Fixtures\ArrayContainer;
use PHPUnit\Framework\TestCase;
use Bluz\Tests\Container\Fixtures\ConcreteContainer;

/**
* Tests for Container traits
* Tests for ArrayContainer
*
* @package Bluz\Tests\Common
*
Expand Down
87 changes: 87 additions & 0 deletions tests/Container/ComplexContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/

namespace Bluz\Tests\Container;

use Bluz\Tests\Container\Fixtures\ComplexContainer;
use PHPUnit\Framework\TestCase;

/**
* Tests for ComplexContainer
*
* @package Bluz\Tests\Common
*
* @author Anton Shevchuk
*/
class ComplexContainerTest extends TestCase
{

/**
* @var ComplexContainer
*/
protected ComplexContainer $class;

protected array $example = [
'foo' => 'bar',
'quz' => 'qux'
];

/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp(): void
{
$this->class = new ComplexContainer();
}

/**
* Test ArrayAccess trait
*/
public function testArrayAccess()
{
$this->class['foo'] = 'bar';
$this->class['quz'] = 'qux';

unset($this->class['quz']);

self::assertEquals('bar', $this->class['foo']);
self::assertFalse(isset($this->class['quz']));
self::assertFalse(isset($this->class['some']));
self::assertEmpty($this->class['quz']);
self::assertEmpty($this->class['some']);
self::assertNull($this->class['quz']);
}

/**
* Test MagicAccess trait
*/
public function testMagicAccess()
{
$this->class->foo = 'bar';
$this->class->quz = 'qux';

unset($this->class->quz);

self::assertEquals('bar', $this->class->foo);
self::assertFalse(isset($this->class->quz));
self::assertFalse(isset($this->class->some));
self::assertEmpty($this->class->quz);
self::assertEmpty($this->class->some);
self::assertNull($this->class->quz);
}

/**
* Test JsonSerialize implementation
*/
public function testJsonSerialize()
{
$this->class->setFromArray($this->example);

self::assertJsonStringEqualsJsonString(json_encode($this->example), json_encode($this->class));
}
}
7 changes: 1 addition & 6 deletions tests/Container/Fixtures/ArrayContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,15 @@
namespace Bluz\Tests\Container\Fixtures;

use Bluz\Container\ArrayAccess;
use Bluz\Container\Container;
use Bluz\Container\JsonSerialize;
use Bluz\Container\MagicAccess;
use Bluz\Container\RegularAccess;

/**
* Concrete class with Container trait
* Concrete class with ArrayAccess trait
*
* @package Bluz\Tests\Common
*
* @author Anton Shevchuk
*/
class ArrayContainer implements \ArrayAccess
{
use Container;
use ArrayAccess;
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@
namespace Bluz\Tests\Container\Fixtures;

use Bluz\Container\ArrayAccess;
use Bluz\Container\Container;
use Bluz\Container\JsonSerialize;
use Bluz\Container\MagicAccess;
use Bluz\Container\RegularAccess;

/**
* Concrete class with Container trait
* Concrete class with all traits
*
* @package Bluz\Tests\Common
*
* @author Anton Shevchuk
*/
class ConcreteContainer implements \JsonSerializable
class ComplexContainer implements \ArrayAccess, \JsonSerializable
{
use Container;
use ArrayAccess;
use JsonSerialize;
use MagicAccess;
use RegularAccess;
}
26 changes: 26 additions & 0 deletions tests/Container/Fixtures/JsonContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/

/**
* @namespace
*/

namespace Bluz\Tests\Container\Fixtures;

use Bluz\Container\JsonSerialize;

/**
* Concrete class with JsonSerialize trait
*
* @package Bluz\Tests\Common
*
* @author Anton Shevchuk
*/
class JsonContainer implements \JsonSerializable
{
use JsonSerialize;
}
7 changes: 1 addition & 6 deletions tests/Container/Fixtures/MagicContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@

namespace Bluz\Tests\Container\Fixtures;

use Bluz\Container\ArrayAccess;
use Bluz\Container\Container;
use Bluz\Container\JsonSerialize;
use Bluz\Container\MagicAccess;
use Bluz\Container\RegularAccess;

/**
* Concrete class with Container trait
* Concrete class with MagicAccess trait
*
* @package Bluz\Tests\Common
*
* @author Anton Shevchuk
*/
class MagicContainer
{
use Container;
use MagicAccess;
}
7 changes: 1 addition & 6 deletions tests/Container/Fixtures/RegularContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,16 @@

namespace Bluz\Tests\Container\Fixtures;

use Bluz\Container\ArrayAccess;
use Bluz\Container\Container;
use Bluz\Container\JsonSerialize;
use Bluz\Container\MagicAccess;
use Bluz\Container\RegularAccess;

/**
* Concrete class with Container trait
* Concrete class with RegularAccess trait
*
* @package Bluz\Tests\Common
*
* @author Anton Shevchuk
*/
class RegularContainer
{
use Container;
use RegularAccess;
}
26 changes: 26 additions & 0 deletions tests/Container/Fixtures/SimpleContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* @copyright Bluz PHP Team
* @link https://github.com/bluzphp/framework
*/

/**
* @namespace
*/

namespace Bluz\Tests\Container\Fixtures;

use Bluz\Container\Container;

/**
* Concrete class with just Container trait
*
* @package Bluz\Tests\Common
*
* @author Anton Shevchuk
*/
class SimpleContainer
{
use Container;
}
Loading

0 comments on commit 9574043

Please sign in to comment.