ChainStorageTest::testUpdateCallAllStorages()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.9666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the PHP Translation package.
5
 *
6
 * (c) PHP Translation team <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Translation\common\tests\Unit\Storage;
13
14
use PHPUnit\Framework\TestCase;
15
use Symfony\Component\Translation\MessageCatalogueInterface;
16
use Translation\Common\Model\Message;
17
use Translation\Common\Storage\ChainStorage;
18
use Translation\Common\Storage\StorageInterface;
19
20
class ChainStorageTest extends TestCase
21
{
22
    private $childStorage1;
23
    private $childStorage2;
24
    private $storage;
25
26
    protected function setUp(): void
27
    {
28
        $this->childStorage1 = $this->prophesize(StorageInterface::class);
29
        $this->childStorage2 = $this->prophesize(StorageInterface::class);
30
31
        $this->storage = new ChainStorage();
32
        $this->storage->addStorage($this->childStorage1->reveal());
33
        $this->storage->addStorage($this->childStorage2->reveal());
34
    }
35
36 View Code Duplication
    public function testGetWithMessageInFirstStorage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $expectedMessage = new Message('PHP Translation IS awesome!');
39
40
        $this->childStorage1->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn($expectedMessage);
41
        $this->childStorage2->get('en', 'messages', 'php_translation_is_awesome')->shouldNotBeCalled();
42
43
        $message = $this->storage->get('en', 'messages', 'php_translation_is_awesome');
44
        $this->assertSame($expectedMessage, $message);
45
    }
46
47 View Code Duplication
    public function testGetWithMessageInSecondStorage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $expectedMessage = new Message('PHP Translation IS awesome!');
50
51
        $this->childStorage1->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn(null);
52
        $this->childStorage2->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn($expectedMessage);
53
54
        $message = $this->storage->get('en', 'messages', 'php_translation_is_awesome');
55
        $this->assertSame($expectedMessage, $message);
56
    }
57
58
    public function testGetWithMessageNotFound()
59
    {
60
        $this->childStorage1->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn(null);
61
        $this->childStorage2->get('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1)->willReturn(null);
62
63
        $message = $this->storage->get('en', 'messages', 'php_translation_is_awesome');
64
        $this->assertNull($message);
65
    }
66
67 View Code Duplication
    public function testCreateCallAllStorages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
68
    {
69
        $message = new Message('PHP Translation IS awesome!');
70
71
        $this->childStorage1->create($message)->shouldBeCalledtimes(1);
72
        $this->childStorage2->create($message)->shouldBeCalledtimes(1);
73
74
        $this->storage->create($message);
75
    }
76
77 View Code Duplication
    public function testUpdateCallAllStorages()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $message = new Message('PHP Translation IS awesome!');
80
81
        $this->childStorage1->update($message)->shouldBeCalledtimes(1);
82
        $this->childStorage2->update($message)->shouldBeCalledtimes(1);
83
84
        $this->storage->update($message);
85
    }
86
87
    public function testDeleteCallAllStorages()
88
    {
89
        $this->childStorage1->delete('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1);
90
        $this->childStorage2->delete('en', 'messages', 'php_translation_is_awesome')->shouldBeCalledtimes(1);
91
92
        $this->storage->delete('en', 'messages', 'php_translation_is_awesome');
93
    }
94
95 View Code Duplication
    public function testExportCallOnlyTransferrableStorage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $messageCatalogue = $this->prophesize(MessageCatalogueInterface::class)->reveal();
98
99
        $this->childStorage2->export($messageCatalogue, [])->shouldBeCalledtimes(1);
100
101
        $this->storage->export($messageCatalogue, []);
102
    }
103
104 View Code Duplication
    public function testImportCallOnlyTransferrableStorage()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
105
    {
106
        $messageCatalogue = $this->prophesize(MessageCatalogueInterface::class)->reveal();
107
108
        $this->childStorage2->import($messageCatalogue, [])->shouldBeCalledtimes(1);
109
110
        $this->storage->import($messageCatalogue, []);
111
    }
112
}
113