Fix bug in style changes for the Use cases on the live site.
[yaffs-website] / vendor / symfony / serializer / Tests / Encoder / ChainDecoderTest.php
1 <?php
2
3 /*
4  * This file is part of the Symfony package.
5  *
6  * (c) Fabien Potencier <fabien@symfony.com>
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 Symfony\Component\Serializer\Tests\Encoder;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Serializer\Encoder\ChainDecoder;
16
17 class ChainDecoderTest extends TestCase
18 {
19     const FORMAT_1 = 'format1';
20     const FORMAT_2 = 'format2';
21     const FORMAT_3 = 'format3';
22
23     private $chainDecoder;
24     private $decoder1;
25     private $decoder2;
26
27     protected function setUp()
28     {
29         $this->decoder1 = $this
30             ->getMockBuilder('Symfony\Component\Serializer\Encoder\DecoderInterface')
31             ->getMock();
32
33         $this->decoder1
34             ->method('supportsDecoding')
35             ->will($this->returnValueMap(array(
36                 array(self::FORMAT_1, true),
37                 array(self::FORMAT_2, false),
38                 array(self::FORMAT_3, false),
39             )));
40
41         $this->decoder2 = $this
42             ->getMockBuilder('Symfony\Component\Serializer\Encoder\DecoderInterface')
43             ->getMock();
44
45         $this->decoder2
46             ->method('supportsDecoding')
47             ->will($this->returnValueMap(array(
48                 array(self::FORMAT_1, false),
49                 array(self::FORMAT_2, true),
50                 array(self::FORMAT_3, false),
51             )));
52
53         $this->chainDecoder = new ChainDecoder(array($this->decoder1, $this->decoder2));
54     }
55
56     public function testSupportsDecoding()
57     {
58         $this->assertTrue($this->chainDecoder->supportsDecoding(self::FORMAT_1));
59         $this->assertTrue($this->chainDecoder->supportsDecoding(self::FORMAT_2));
60         $this->assertFalse($this->chainDecoder->supportsDecoding(self::FORMAT_3));
61     }
62
63     public function testDecode()
64     {
65         $this->decoder1->expects($this->never())->method('decode');
66         $this->decoder2->expects($this->once())->method('decode');
67
68         $this->chainDecoder->decode('string_to_decode', self::FORMAT_2);
69     }
70
71     /**
72      * @expectedException \Symfony\Component\Serializer\Exception\RuntimeException
73      */
74     public function testDecodeUnsupportedFormat()
75     {
76         $this->chainDecoder->decode('string_to_decode', self::FORMAT_3);
77     }
78 }