2 namespace Consolidation\OutputFormatters;
4 use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
5 use Consolidation\OutputFormatters\StructuredData\PropertyList;
6 use Consolidation\OutputFormatters\Exception\IncompatibleDataException;
8 class IncompatibleDataTests extends \PHPUnit_Framework_TestCase
10 protected $formatterManager;
13 $this->formatterManager = new FormatterManager();
16 protected function assertIncompatibleDataMessage($expected, $formatter, $data)
18 $e = new IncompatibleDataException($formatter, $data, $formatter->validDataTypes());
19 $this->assertEquals($expected, $e->getMessage());
22 public function testIncompatibleData()
24 $tableFormatter = $this->formatterManager->getFormatter('table');
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([]));
33 * @expectedException \Exception
34 * @expectedExceptionMessage Undescribable data error: NULL
36 public function testUndescribableData()
38 $tableFormatter = $this->formatterManager->getFormatter('table');
39 $data = $tableFormatter->validate(null);
40 $this->assertEquals('Will throw before comparing.', $data);
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.
47 public function testInvalidTableData()
49 $tableFormatter = $this->formatterManager->getFormatter('table');
50 $data = $tableFormatter->validate('bad data type');
51 $this->assertEquals('Will throw before comparing.', $data);
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.
58 public function testInvalidSectionsData()
60 $tableFormatter = $this->formatterManager->getFormatter('sections');
61 $data = $tableFormatter->validate('bad data type');
62 $this->assertEquals('Will throw before comparing.', $data);