/**
  * @covers \PhpCqrs\Domain\Identifier\Exception\NonStringIdentifier::forNonString
  */
 public function testCanConstructForNonString()
 {
     $exception = NonStringIdentifier::forNonString(1337);
     $this->assertInstanceOf(NonStringIdentifier::class, $exception);
     $this->assertSame('Non string identifier, got integer.', $exception->getMessage());
     $exception = NonStringIdentifier::forNonString(new stdClass());
     $this->assertSame('Non string identifier, got stdClass.', $exception->getMessage());
 }
Пример #2
0
 /**
  * @param string $identifier
  * @throws NonStringIdentifier
  */
 public function __construct($identifier)
 {
     if (!is_string($identifier)) {
         throw NonStringIdentifier::forNonString($identifier);
     }
     if (empty($identifier)) {
         throw NonStringIdentifier::forEmptyString();
     }
     $this->identifier = (string) $identifier;
 }