/
ResolveCacheTest.php
95 lines (76 loc) · 3.56 KB
/
ResolveCacheTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace Liip\ImagineBundle\Tests\Async;
use Enqueue\Bundle\EnqueueBundle;
use Liip\ImagineBundle\Async\ResolveCache;
class ResolveCacheTest extends \PHPUnit\Framework\TestCase
{
public static function setUpBeforeClass()
{
if (!class_exists(EnqueueBundle::class)) {
self::markTestSkipped('The tests are run without enqueue integration. Skip them');
}
}
public function testCouldBeJsonSerializedWithoutFiltersAndForce()
{
$message = new ResolveCache('thePath');
$this->assertEquals('{"path":"thePath","filters":null,"force":false}', json_encode($message));
}
public function testCouldBeJsonSerializedWithFilters()
{
$message = new ResolveCache('thePath', array('fooFilter', 'barFilter'));
$this->assertEquals('{"path":"thePath","filters":["fooFilter","barFilter"],"force":false}', json_encode($message));
}
public function testCouldBeJsonSerializedWithFiltersAndForce()
{
$message = new ResolveCache('thePath', array('fooFilter', 'barFilter'), true);
$this->assertEquals('{"path":"thePath","filters":["fooFilter","barFilter"],"force":true}', json_encode($message));
}
public function testCouldBeJsonDeSerializedWithoutFiltersAndForce()
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath","filters":null,"force":false}');
$this->assertInstanceOf('Liip\ImagineBundle\Async\ResolveCache', $message);
$this->assertEquals('thePath', $message->getPath());
$this->assertNull($message->getFilters());
$this->assertFalse($message->isForce());
}
public function testCouldBeJsonDeSerializedWithFilters()
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath","filters":["fooFilter","barFilter"],"force":false}');
$this->assertInstanceOf('Liip\ImagineBundle\Async\ResolveCache', $message);
$this->assertEquals('thePath', $message->getPath());
$this->assertEquals(array('fooFilter', 'barFilter'), $message->getFilters());
$this->assertFalse($message->isForce());
}
public function testCouldBeJsonDeSerializedWithFiltersAndForce()
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath","filters":["fooFilter","barFilter"],"force":true}');
$this->assertInstanceOf('Liip\ImagineBundle\Async\ResolveCache', $message);
$this->assertEquals('thePath', $message->getPath());
$this->assertEquals(array('fooFilter', 'barFilter'), $message->getFilters());
$this->assertTrue($message->isForce());
}
public function testCouldBeJsonDeSerializedWithOnlyPath()
{
$message = ResolveCache::jsonDeserialize('{"path":"thePath"}');
$this->assertInstanceOf('Liip\ImagineBundle\Async\ResolveCache', $message);
$this->assertEquals('thePath', $message->getPath());
$this->assertNull($message->getFilters());
$this->assertFalse($message->isForce());
}
/**
* @expectedException \Liip\ImagineBundle\Exception\LogicException
* @expectedExceptionMessage The message does not contain "path" but it is required.
*/
public function testThrowIfMessageMissingPathOnJsonDeserialize()
{
ResolveCache::jsonDeserialize('{}');
}
/**
* @expectedException \Liip\ImagineBundle\Exception\LogicException
* @expectedExceptionMessage The message filters could be either null or array.
*/
public function testThrowIfMessageContainsNotSupportedFilters()
{
ResolveCache::jsonDeserialize('{"path": "aPath", "filters": "stringFilterIsNotAllowed"}');
}
}