*/ class VendorTest extends TestCase { /** * Test the good constructing of vendor * * @dataProvider getGoodConstructorData * @author Phil Burton * @param string $name * @param string $postcode * @param int maxCovers */ public function testGoodConstructor($name, $postcode, $maxCovers) { // create new vendor $vendor = new Vendor($name, $postcode, $maxCovers); // use reflection to get values of protected properties $reflectionClass = new ReflectionClass(Vendor::class); // Check name has been set correctly $nameProperty = $reflectionClass->getProperty('name'); $nameProperty->setAccessible(true); $nameValue = $nameProperty->getValue($vendor); $this->assertEquals($nameValue, $name); // Check postcode has been set correctly $postcodeProperty = $reflectionClass->getProperty('postcode'); $postcodeProperty->setAccessible(true); $postcodeValue = $postcodeProperty->getValue($vendor); $this->assertEquals($postcodeValue, $postcode); // Check maxCovers has been set correctly $maxCoversProperty = $reflectionClass->getProperty('maxCovers'); $maxCoversProperty->setAccessible(true); $maxCoversValue = $maxCoversProperty->getValue($vendor); $this->assertEquals($maxCoversValue, $maxCovers); // Check the menus array is initalised to an empty array $mensuProperty = $reflectionClass->getProperty('menus'); $mensuProperty->setAccessible(true); $menusValue = $mensuProperty->getValue($vendor); $this->assertEquals($menusValue, []); } /** * Data for testing good constcutor * * @author Phil Burton * @return mixed[] */ public function getGoodConstructorData() { return [ ['a', 'b', 1], ['1', '2', 3], ['A very long name with spaces in it', 'SW111TH', 10000000], ]; } /** * Test the check location * * @dataProvider getLocationData * @author Phil Burton */ public function testCheckLocation($postcode, $postcodePart, $expectedResult) { $vendor = new Vendor('name', $postcode, 1); $this->assertEquals($vendor->checkLocation($postcodePart), $expectedResult); } /** * Return the location data for test * * @author Phil Burton * @return mixed[] */ public function getLocationData() { return [ ['SW111TH', 'SW', true], ['SW11 1TH', 'SW', true], ['sw111th', 'SW', true], ['sW111TH', 'SW', true], ['SW11 1TH', 'sw', true], ['sw11 1th', 'sw', true], ['SW', 'SW', true], ['SE111TH', 'SW', false], ['SW111TH', 'se', false], ['0000SW', 'SW', false], ]; } }