/** * @param string $commandClassName * * @return string */ private function getExpectedHandlerName($commandClassName) { $commandClassName = ClassUtils::shortName($commandClassName); if ('Command' === substr($commandClassName, -7)) { $commandClassName = substr($commandClassName, 0, -7); } return $commandClassName . 'CommandHandler'; }
public function testShortName() { $object = new CommandHandlerLocator(); $this->assertEquals('CommandHandlerLocator', ClassUtils::shortName($object), 'passing an object should return the class name without namespace'); $this->assertEquals('CommandHandlerLocator', ClassUtils::shortName('PhpDDD\\Command\\Handler\\Locator\\CommandHandlerLocator'), 'passing the fully qualified namespace should return the class name without namespace'); $this->assertEquals('CommandHandlerLocator', ClassUtils::shortName(get_class($object)), 'using get_class should return the class name without namespace'); $assertException = false; try { ClassUtils::shortName('This\\Class\\Does\\Not\\Exists'); } catch (InvalidArgumentException $exception) { $assertException = true; } $this->assertTrue($assertException, 'A class that does not exists should raise an exception'); }