Skip to content

Commit c81bc96

Browse files
committed
Release of version 4.0.0
1 parent 7ba3729 commit c81bc96

File tree

9 files changed

+505
-7
lines changed

9 files changed

+505
-7
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [3.0.0] - 2020-02-
7+
## [4.0.0]
8+
### Changed
9+
- minimum php version is now 8.0
10+
11+
## [3.0.0] - 2020-03-03
812
### Changed
913
- minimum php version is now 7.2
1014
### Removed
@@ -42,6 +46,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4246
- `is any` and `is every` twig test
4347
- `=>`, `;` twig operator
4448

49+
[4.0.0]: https://github.com/leonaero/twig-lambda/compare/v4.0.0...v3.0.0
4550
[3.0.0]: https://github.com/leonaero/twig-lambda/compare/v3.0.0...v2.1.0
4651
[2.1.0]: https://github.com/leonaero/twig-lambda/compare/v2.0.0...v2.1.0
4752
[2.0.0]: https://github.com/leonaero/twig-lambda/compare/v1.1.0...v2.0.0

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM php:7.2-fpm-alpine
1+
FROM php:8.0-fpm-alpine
22

33
RUN apk update && apk add --no-cache \
44
bash \

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
| Version | Twig Version | Php Version |
66
|---- |----|----|
7-
| ^3.0 | ^3.0 | ^7.2 |
7+
| ^3.0 | ^3.0 | ^7.2 || ^8.0 |
88
| ^2.0 | ^2.10 | ^7.0 |
99
| ^1.0 | ^1.0 || 2.9.* | ^5.6 || ^7.0 |
1010

Tests/DictionaryIteratorTest.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace LeonAero\TwigLambda\Tests;
6+
7+
use LeonAero\TwigLambda\Dictionary;
8+
use LeonAero\TwigLambda\DictionaryIterator;
9+
use PHPUnit\Framework\TestCase;
10+
use stdClass;
11+
12+
class DictionaryIteratorTest extends TestCase
13+
{
14+
public function testIterator(): void
15+
{
16+
$object1 = new stdClass();
17+
$object2 = new stdClass();
18+
$object3 = new stdClass();
19+
20+
$d = new Dictionary();
21+
$d[4] = $object1;
22+
$d['abc'] = $object2;
23+
$d[$object3] = $this;
24+
25+
$it = new DictionaryIterator($d);
26+
27+
$it->rewind();
28+
self::assertSame(4, $it->key());
29+
self::assertSame($object1, $it->current());
30+
self::assertTrue($it->valid());
31+
32+
$it->next();
33+
self::assertSame('abc', $it->key());
34+
self::assertSame($object2, $it->current());
35+
self::assertTrue($it->valid());
36+
37+
$it->next();
38+
self::assertSame($object3, $it->key());
39+
self::assertSame($this, $it->current());
40+
self::assertTrue($it->valid());
41+
42+
$it->next();
43+
self::assertFalse($it->valid());
44+
45+
$it->rewind();
46+
self::assertTrue($it->valid());
47+
}
48+
}

Tests/DictionaryTest.php

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
<?php
2+
3+
namespace LeonAero\TwigLambda\Tests;
4+
5+
6+
use ArrayIterator;
7+
use InvalidArgumentException;
8+
use LeonAero\TwigLambda\Dictionary;
9+
use PHPUnit\Framework\TestCase;
10+
use stdClass;
11+
12+
class DictionaryTest extends TestCase
13+
{
14+
15+
/**
16+
* @dataProvider getOffsets
17+
*/
18+
public function testArrayAccess($offset): void
19+
{
20+
$d = new Dictionary();
21+
self::assertFalse($d->offsetExists($offset));
22+
23+
$d->offsetSet($offset, 34);
24+
self::assertTrue($d->offsetExists($offset));
25+
self::assertEquals(34, $d->offsetGet($offset));
26+
27+
$d->offsetUnset($offset);
28+
self::assertFalse($d->offsetExists($offset));
29+
}
30+
31+
public function getOffsets(): array
32+
{
33+
return [
34+
'int' => [12],
35+
'object' => [new stdClass()],
36+
'string' => ['foobar'],
37+
'bool' => [true],
38+
'null' => [null],
39+
'float' => [1.4],
40+
];
41+
}
42+
43+
/**
44+
* Check if Dictionary recognize difference between
45+
* key types.
46+
*/
47+
public function testKeyTypeAwareness(): void
48+
{
49+
$keys = [
50+
1,
51+
0,
52+
true,
53+
false,
54+
'1',
55+
'0',
56+
1.0,
57+
0.0,
58+
null,
59+
];
60+
61+
$d = new Dictionary();
62+
foreach ($keys as $value => $key) {
63+
$d[$key] = $value;
64+
}
65+
66+
foreach ($keys as $value => $key) {
67+
self::assertEquals($value, $d[$key]);
68+
}
69+
}
70+
71+
public function testCount(): void
72+
{
73+
$d = new Dictionary();
74+
75+
self::assertEquals(0, $d->count());
76+
77+
$d[1] = 12;
78+
$d[true] = new stdClass();
79+
$d[false] = new stdClass();
80+
$d['false'] = 'abc';
81+
$d['1'] = 'def';
82+
$d[null] = 13;
83+
$d[new stdClass()] = 1;
84+
85+
self::assertEquals(7, $d->count());
86+
}
87+
88+
/**
89+
* @dataProvider getInvalidOffsets
90+
*/
91+
public function testOffsetSet_InvalidOffset_ThrowException($offset): void
92+
{
93+
$this->expectException(InvalidArgumentException::class);
94+
$d = new Dictionary();
95+
$d[$offset] = 1;
96+
}
97+
98+
/**
99+
* @dataProvider getInvalidOffsets
100+
*/
101+
public function testOffsetGet_InvalidOffset_ThrowException($offset): void
102+
{
103+
$this->expectException(InvalidArgumentException::class);
104+
$d = new Dictionary();
105+
$d[$offset];
106+
}
107+
108+
/**
109+
* @dataProvider getInvalidOffsets
110+
*/
111+
public function testOffsetExists_InvalidOffset_ThrowException($offset): void
112+
{
113+
$this->expectException(InvalidArgumentException::class);
114+
$d = new Dictionary();
115+
isset($d[$offset]);
116+
}
117+
118+
/**
119+
* @dataProvider getInvalidOffsets
120+
*/
121+
public function testOffsetUnset_InvalidOffset_ThrowException($offset): void
122+
{
123+
$this->expectException(InvalidArgumentException::class);
124+
$d = new Dictionary();
125+
unset($d[$offset]);
126+
}
127+
128+
public function getInvalidOffsets(): array
129+
{
130+
return [
131+
'array' => [[1, 2, 3]],
132+
'Closure' => [
133+
static function () {
134+
}
135+
],
136+
];
137+
}
138+
139+
public function testFromArray_CreateFromArray(): void
140+
{
141+
$array = [
142+
'ab' => new stdClass(),
143+
12 => 'cd',
144+
0 => 'ef',
145+
'gh' => 10.2,
146+
];
147+
$d = Dictionary::fromArray($array);
148+
149+
self::assertSame($array['ab'], $d['ab']);
150+
self::assertSame($array[12], $d[12]);
151+
self::assertSame($array[0], $d[0]);
152+
self::assertSame($array['gh'], $d['gh']);
153+
self::assertEquals(4, $d->count());
154+
}
155+
156+
public function testFromArray_CreateFromTraversable(): void
157+
{
158+
$array = [
159+
'ab' => new stdClass(),
160+
12 => 'cd',
161+
0 => 'ef',
162+
'gh' => 10.2,
163+
];
164+
$d = Dictionary::fromArray(new ArrayIterator($array));
165+
166+
self::assertSame($array['ab'], $d['ab']);
167+
self::assertSame($array[12], $d[12]);
168+
self::assertSame($array[0], $d[0]);
169+
self::assertSame($array['gh'], $d['gh']);
170+
self::assertEquals(4, $d->count());
171+
}
172+
173+
/**
174+
* @dataProvider getInvalidArrays
175+
*/
176+
public function testFromArray_InvalidArray_ThrowException($array): void
177+
{
178+
$this->expectException(InvalidArgumentException::class);
179+
Dictionary::fromArray($array);
180+
}
181+
182+
public function getInvalidArrays(): array
183+
{
184+
return [
185+
'int' => [12],
186+
'float' => [1.2],
187+
'string' => ['abcdef'],
188+
'object' => [new stdClass()],
189+
'null' => [null],
190+
'false' => [false],
191+
'true' => [true],
192+
];
193+
}
194+
195+
public function testUnserialize(): void
196+
{
197+
$serialized = 'C:30:"LeonAero\TwigLambda\Dictionary":203:{a:5:{i:0;a:2:{i:0;O:8:"stdClass":0:{}i:1;i:12;}i:1;a:2:{i:0;s:3:"foo";i:1;s:3:"bar";}i:2;a:2:{i:0;O:8:"stdClass":0:{}i:1;s:3:"tet";}i:3;a:2:{i:0;i:12;i:1;O:8:"stdClass":0:{}}i:4;a:2:{i:0;i:15;i:1;r:14;}}}';
198+
/* @var $d Dictionary */
199+
$d = unserialize($serialized);
200+
201+
self::assertEquals('bar', $d['foo']);
202+
self::assertSame($d[12], $d[15]);
203+
self::assertCount(5, $d);
204+
205+
$it = $d->getIterator();
206+
207+
$it->rewind();
208+
$obj1 = $it->key();
209+
self::assertEquals(12, $it->current());
210+
$it->next();
211+
$it->next();
212+
$obj2 = $it->key();
213+
self::assertEquals('tet', $it->current());
214+
self::assertNotSame($obj1, $obj2);
215+
}
216+
217+
}

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@
1212
"prefer-stable": true,
1313
"license": "MIT",
1414
"require": {
15-
"php": "^7.2.5",
16-
"twig/twig": "^3.0",
17-
"dpolac/dictionary": "^1.0"
15+
"php": "^8.0",
16+
"twig/twig": "^3.0"
1817
},
1918
"require-dev": {
2019
"phpunit/phpunit": "^8.5"

0 commit comments

Comments
 (0)