d38f96200dc2f957ad46334263202d00b268c123
[yaffs-website] / vendor / consolidation / output-formatters / tests / testIncompatibleData.php
1 <?php
2 namespace Consolidation\OutputFormatters;
3
4 use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
5 use Consolidation\OutputFormatters\StructuredData\PropertyList;
6 use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
7
8 class IncompatibleDataTests extends \PHPUnit_Framework_TestCase
9 {
10     protected $formatterManager;
11
12     function setup() {
13         $this->formatterManager = new FormatterManager();
14     }
15
16     protected function assertIncompatibleDataMessage($expected, $formatter, $data)
17     {
18         $e = new IncompatibleDataException($formatter, $data, $formatter->validDataTypes());
19         $this->assertEquals($expected, $e->getMessage());
20     }
21
22     public function testIncompatibleData()
23     {
24         $tableFormatter = $this->formatterManager->getFormatter('table');
25
26         $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, a string was provided.', $tableFormatter, 'a string');
27         $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, an instance of Consolidation\OutputFormatters\FormatterManager was provided.', $tableFormatter, $this->formatterManager);
28         $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, an array was provided.', $tableFormatter, []);
29         $this->assertIncompatibleDataMessage('Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, an instance of Consolidation\OutputFormatters\StructuredData\PropertyList was provided.', $tableFormatter, new PropertyList([]));
30     }
31
32     /**
33      * @expectedException \Exception
34      * @expectedExceptionMessage Undescribable data error: NULL
35      */
36     public function testUndescribableData()
37     {
38         $tableFormatter = $this->formatterManager->getFormatter('table');
39         $data = $tableFormatter->validate(null);
40         $this->assertEquals('Will throw before comparing.', $data);
41     }
42
43     /**
44      * @expectedException \Exception
45      * @expectedExceptionMessage Data provided to Consolidation\OutputFormatters\Formatters\TableFormatter must be either an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields or an instance of Consolidation\OutputFormatters\StructuredData\PropertyList. Instead, a string was provided.
46      */
47     public function testInvalidTableData()
48     {
49         $tableFormatter = $this->formatterManager->getFormatter('table');
50         $data = $tableFormatter->validate('bad data type');
51         $this->assertEquals('Will throw before comparing.', $data);
52     }
53
54     /**
55      * @expectedException \Exception
56      * @expectedExceptionMessage Data provided to Consolidation\OutputFormatters\Formatters\SectionsFormatter must be an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields. Instead, a string was provided.
57      */
58     public function testInvalidSectionsData()
59     {
60         $tableFormatter = $this->formatterManager->getFormatter('sections');
61         $data = $tableFormatter->validate('bad data type');
62         $this->assertEquals('Will throw before comparing.', $data);
63     }
64 }