summaryrefslogtreecommitdiff
path: root/tests/unit/VendorTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/unit/VendorTest.php')
-rw-r--r--tests/unit/VendorTest.php110
1 files changed, 110 insertions, 0 deletions
diff --git a/tests/unit/VendorTest.php b/tests/unit/VendorTest.php
new file mode 100644
index 0000000..de58110
--- /dev/null
+++ b/tests/unit/VendorTest.php
@@ -0,0 +1,110 @@
+<?php
+
+namespace App\Unit;
+
+use PHPUnit\Framework\TestCase;
+use ReflectionClass;
+use App\Model\Vendor;
+
+/**
+ * Tet the vedor class
+ *
+ * @author Phil Burton <phil@pgburton.com>
+ */
+class VendorTest extends TestCase
+{
+ /**
+ * Test the good constructing of vendor
+ *
+ * @dataProvider getGoodConstructorData
+ * @author Phil Burton <phil@pgburton.com>
+ * @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 <phil@pgburton.com>
+ * @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 <phil@pgburton.com>
+ */
+ 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 <phil@pgburton.com>
+ * @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],
+ ];
+ }
+}