diff --git a/src/Breadcrumbs/Breadcrumb.php b/src/Breadcrumbs/Breadcrumb.php index 3c35cdb0..ee107933 100644 --- a/src/Breadcrumbs/Breadcrumb.php +++ b/src/Breadcrumbs/Breadcrumb.php @@ -117,8 +117,17 @@ class Breadcrumb */ public function __construct($name, $type, array $metaData = []) { - if (!is_string($name) || $name === '') { - throw new InvalidArgumentException('The breadcrumb name must be a non-empty string.'); + if (!is_string($name)) { + if (is_null($name)) { + $metaData['BreadcrumbError'] = 'NULL provided as the breadcrumb name'; + $name = ''; + } else { + $metaData['BreadcrumbError'] = 'Breadcrumb name must be a string - '.gettype($name).' provided instead'; + $name = ''; + } + } elseif ($name === '') { + $metaData['BreadcrumbError'] = 'Empty string provided as the breadcrumb name'; + $name = ''; } if (strlen($name) > static::MAX_LENGTH) { diff --git a/tests/Breadcrumbs/BreadcrumbTest.php b/tests/Breadcrumbs/BreadcrumbTest.php index fbb3a1be..332f0913 100644 --- a/tests/Breadcrumbs/BreadcrumbTest.php +++ b/tests/Breadcrumbs/BreadcrumbTest.php @@ -7,22 +7,25 @@ class BreadcrumbTest extends TestCase { - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The breadcrumb name must be a non-empty string. - */ public function testBadName() { - new Breadcrumb(123, 'error'); + $breadcrumb = new Breadcrumb(123, 'error'); + $this->assertSame('', $breadcrumb->toArray()['name']); + $this->assertSame('Breadcrumb name must be a string - integer provided instead', $breadcrumb->getMetaData()['BreadcrumbError']); } - /** - * @expectedException \InvalidArgumentException - * @expectedExceptionMessage The breadcrumb name must be a non-empty string. - */ public function testEmptyName() { - new Breadcrumb('', 'error'); + $breadcrumb = new Breadcrumb('', 'error'); + $this->assertSame('', $breadcrumb->toArray()['name']); + $this->assertSame('Empty string provided as the breadcrumb name', $breadcrumb->getMetaData()['BreadcrumbError']); + } + + public function testNullName() + { + $breadcrumb = new Breadcrumb(null, 'error'); + $this->assertSame('', $breadcrumb->toArray()['name']); + $this->assertSame('NULL provided as the breadcrumb name', $breadcrumb->getMetaData()['BreadcrumbError']); } /**