X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fconsolidation%2Foutput-formatters%2Ftests%2FtestIncompatibleData.php;fp=vendor%2Fconsolidation%2Foutput-formatters%2Ftests%2FtestIncompatibleData.php;h=d38f96200dc2f957ad46334263202d00b268c123;hp=0000000000000000000000000000000000000000;hb=a2bd1bf0c2c1f1a17d188f4dc0726a45494cefae;hpb=57c063afa3f66b07c4bbddc2d6129a96d90f0aad diff --git a/vendor/consolidation/output-formatters/tests/testIncompatibleData.php b/vendor/consolidation/output-formatters/tests/testIncompatibleData.php new file mode 100644 index 000000000..d38f96200 --- /dev/null +++ b/vendor/consolidation/output-formatters/tests/testIncompatibleData.php @@ -0,0 +1,64 @@ +formatterManager = new FormatterManager(); + } + + protected function assertIncompatibleDataMessage($expected, $formatter, $data) + { + $e = new IncompatibleDataException($formatter, $data, $formatter->validDataTypes()); + $this->assertEquals($expected, $e->getMessage()); + } + + public function testIncompatibleData() + { + $tableFormatter = $this->formatterManager->getFormatter('table'); + + $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'); + $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); + $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, []); + $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([])); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Undescribable data error: NULL + */ + public function testUndescribableData() + { + $tableFormatter = $this->formatterManager->getFormatter('table'); + $data = $tableFormatter->validate(null); + $this->assertEquals('Will throw before comparing.', $data); + } + + /** + * @expectedException \Exception + * @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. + */ + public function testInvalidTableData() + { + $tableFormatter = $this->formatterManager->getFormatter('table'); + $data = $tableFormatter->validate('bad data type'); + $this->assertEquals('Will throw before comparing.', $data); + } + + /** + * @expectedException \Exception + * @expectedExceptionMessage Data provided to Consolidation\OutputFormatters\Formatters\SectionsFormatter must be an instance of Consolidation\OutputFormatters\StructuredData\RowsOfFields. Instead, a string was provided. + */ + public function testInvalidSectionsData() + { + $tableFormatter = $this->formatterManager->getFormatter('sections'); + $data = $tableFormatter->validate('bad data type'); + $this->assertEquals('Will throw before comparing.', $data); + } +}