diff --git a/app/Events/User/UserEventInterface.php b/app/Events/User/UserEventInterface.php new file mode 100644 index 00000000..f9f88df3 --- /dev/null +++ b/app/Events/User/UserEventInterface.php @@ -0,0 +1,17 @@ + + */ +abstract class AbstractAnemicTestCase extends AbstractTestCase +{ + public function testClassIsFinal() + { + $rc = new ReflectionClass($this->getObjectAndParams()['object']); + + $this->assertTrue($rc->isFinal()); + } + + public function testPropertiesMatchTheConstructor() + { + $rc = new ReflectionClass($this->getObjectAndParams()['object']); + + $properties = array_map(function ($property) { + return $property->getName(); + }, $rc->getProperties()); + + $params = array_map(function ($param) { + return $param->getName(); + }, $rc->getMethod('__construct')->getParameters()); + + if ($this->objectHasRules()) { + $params[] = 'rules'; + } + + $this->assertSame($properties, $params); + } + + public function testPropertiesAreCorrectlyDefined() + { + $rc = new ReflectionClass($this->getObjectAndParams()['object']); + + foreach ($rc->getProperties() as $property) { + $this->assertTrue($property->isPublic()); + $this->assertFalse($property->isStatic()); + } + } + + public function testPropertyAccessBehavesCorrectly() + { + extract($this->getObjectAndParams()); + + foreach ($params as $key => $value) { + $this->assertSame($value, $object->{$key}); + } + } +} diff --git a/tests/Events/AbstractEventTestCase.php b/tests/Events/AbstractEventTestCase.php new file mode 100644 index 00000000..3dd75ce0 --- /dev/null +++ b/tests/Events/AbstractEventTestCase.php @@ -0,0 +1,54 @@ + + */ +abstract class AbstractEventTestCase extends AbstractAnemicTestCase +{ + protected function objectHasRules() + { + return false; + } + + public function testEventImplementsTheCorrectInterfaces() + { + $event = $this->getObjectAndParams()['object']; + + foreach ($this->getEventInterfaces() as $interface) { + $this->assertInstanceOf($interface, $event); + } + } + + /*public function testEventHasRegisteredHandlers() + { + $property = (new ReflectionClass(EventServiceProvider::class))->getProperty('listen'); + $property->setAccessible(true); + + $class = get_class($this->getObjectAndParams()['object']); + $mappings = $property->getValue(new EventServiceProvider($this->app)); + + $this->assertTrue(isset($mappings[$class])); + $this->assertGreaterThan(0, count($mappings[$class])); + + foreach ($mappings[$class] as $handler) { + $this->assertInstanceOf($handler, $this->app->make($handler)); + } + }*/ +} diff --git a/tests/Events/User/AbstractUserEventTestCase.php b/tests/Events/User/AbstractUserEventTestCase.php new file mode 100644 index 00000000..c257749f --- /dev/null +++ b/tests/Events/User/AbstractUserEventTestCase.php @@ -0,0 +1,23 @@ + new User()]; + $object = new UserWasAddedEvent($params['user']); + + return compact('params', 'object'); + } +}