Skip to content

Commit 9574043

Browse files
committed
Migrate to PHP 8.2
Migrate to PHPUnit 11 Migrate to usage trait in trait (to simplify usage)
1 parent 35c5b66 commit 9574043

20 files changed

Lines changed: 224 additions & 69 deletions

.scrutinizer.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
build:
22
environment:
3-
php: 8.1
3+
php: 8.2
44
nodes:
55
analysis:
66
tests:

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
"description": "Container package",
44
"type": "library",
55
"require": {
6-
"php": ">=8.1"
6+
"php": ">=8.2"
77
},
88
"require-dev": {
9-
"phpunit/phpunit": "~10.4"
9+
"phpunit/phpunit": "~11.3"
1010
},
1111
"autoload": {
1212
"psr-4": {

src/Container/ArrayAccess.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,11 @@
1919
* @package Bluz\Common
2020
* @author Anton Shevchuk
2121
* @see ArrayAccess
22-
*
23-
* @method void doSetContainer(string $key, mixed $value)
24-
* @method mixed doGetContainer(string $key)
25-
* @method bool doContainsContainer(string $key)
26-
* @method void doDeleteContainer(string $key)
2722
*/
2823
trait ArrayAccess
2924
{
25+
use Container;
26+
3027
/**
3128
* Offset to set
3229
*

src/Container/Container.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
namespace Bluz\Container;
1313

1414
/**
15-
* Container of data for object
15+
* Container of data for an object
1616
*
1717
* @package Bluz\Common
1818
* @author Anton Shevchuk
@@ -102,7 +102,7 @@ public function toArray(): array
102102
}
103103

104104
/**
105-
* Reset container array
105+
* Reset the container array
106106
*
107107
* @return void
108108
*/

src/Container/JsonSerialize.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@
1717
* @package Bluz\Common
1818
* @author Anton Shevchuk
1919
* @see JsonSerializable
20-
*
21-
* @method array toArray()
2220
*/
2321
trait JsonSerialize
2422
{
23+
use Container;
24+
2525
/**
2626
* Specify data which should be serialized to JSON
2727
*

src/Container/MagicAccess.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616
*
1717
* @package Bluz\Common
1818
* @author Anton Shevchuk
19-
*
20-
* @method void doSetContainer(string $key, mixed $value)
21-
* @method mixed doGetContainer(string $key)
22-
* @method bool doContainsContainer(string $key)
23-
* @method void doDeleteContainer(string $key)
2419
*/
2520
trait MagicAccess
2621
{
22+
use Container;
23+
2724
/**
2825
* Magic alias for set() regular method
2926
*

src/Container/RegularAccess.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,11 @@
1616
*
1717
* @package Bluz\Common
1818
* @author Anton Shevchuk
19-
*
20-
* @method void doSetContainer(string $key, mixed $value)
21-
* @method mixed doGetContainer(string $key)
22-
* @method bool doContainsContainer(string $key)
23-
* @method void doDeleteContainer(string $key)
2419
*/
2520
trait RegularAccess
2621
{
22+
use Container;
23+
2724
/**
2825
* Set key/value pair
2926
*

tests/Container/ArrayContainerTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99

1010
use Bluz\Tests\Container\Fixtures\ArrayContainer;
1111
use PHPUnit\Framework\TestCase;
12-
use Bluz\Tests\Container\Fixtures\ConcreteContainer;
1312

1413
/**
15-
* Tests for Container traits
14+
* Tests for ArrayContainer
1615
*
1716
* @package Bluz\Tests\Common
1817
*
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
/**
4+
* @copyright Bluz PHP Team
5+
* @link https://github.com/bluzphp/framework
6+
*/
7+
8+
namespace Bluz\Tests\Container;
9+
10+
use Bluz\Tests\Container\Fixtures\ComplexContainer;
11+
use PHPUnit\Framework\TestCase;
12+
13+
/**
14+
* Tests for ComplexContainer
15+
*
16+
* @package Bluz\Tests\Common
17+
*
18+
* @author Anton Shevchuk
19+
*/
20+
class ComplexContainerTest extends TestCase
21+
{
22+
23+
/**
24+
* @var ComplexContainer
25+
*/
26+
protected ComplexContainer $class;
27+
28+
protected array $example = [
29+
'foo' => 'bar',
30+
'quz' => 'qux'
31+
];
32+
33+
/**
34+
* Sets up the fixture, for example, opens a network connection.
35+
* This method is called before a test is executed.
36+
*/
37+
protected function setUp(): void
38+
{
39+
$this->class = new ComplexContainer();
40+
}
41+
42+
/**
43+
* Test ArrayAccess trait
44+
*/
45+
public function testArrayAccess()
46+
{
47+
$this->class['foo'] = 'bar';
48+
$this->class['quz'] = 'qux';
49+
50+
unset($this->class['quz']);
51+
52+
self::assertEquals('bar', $this->class['foo']);
53+
self::assertFalse(isset($this->class['quz']));
54+
self::assertFalse(isset($this->class['some']));
55+
self::assertEmpty($this->class['quz']);
56+
self::assertEmpty($this->class['some']);
57+
self::assertNull($this->class['quz']);
58+
}
59+
60+
/**
61+
* Test MagicAccess trait
62+
*/
63+
public function testMagicAccess()
64+
{
65+
$this->class->foo = 'bar';
66+
$this->class->quz = 'qux';
67+
68+
unset($this->class->quz);
69+
70+
self::assertEquals('bar', $this->class->foo);
71+
self::assertFalse(isset($this->class->quz));
72+
self::assertFalse(isset($this->class->some));
73+
self::assertEmpty($this->class->quz);
74+
self::assertEmpty($this->class->some);
75+
self::assertNull($this->class->quz);
76+
}
77+
78+
/**
79+
* Test JsonSerialize implementation
80+
*/
81+
public function testJsonSerialize()
82+
{
83+
$this->class->setFromArray($this->example);
84+
85+
self::assertJsonStringEqualsJsonString(json_encode($this->example), json_encode($this->class));
86+
}
87+
}

tests/Container/Fixtures/ArrayContainer.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,15 @@
1212
namespace Bluz\Tests\Container\Fixtures;
1313

1414
use Bluz\Container\ArrayAccess;
15-
use Bluz\Container\Container;
16-
use Bluz\Container\JsonSerialize;
17-
use Bluz\Container\MagicAccess;
18-
use Bluz\Container\RegularAccess;
1915

2016
/**
21-
* Concrete class with Container trait
17+
* Concrete class with ArrayAccess trait
2218
*
2319
* @package Bluz\Tests\Common
2420
*
2521
* @author Anton Shevchuk
2622
*/
2723
class ArrayContainer implements \ArrayAccess
2824
{
29-
use Container;
3025
use ArrayAccess;
3126
}

0 commit comments

Comments
 (0)