From dc29a6134b1890cf0ea8d07b59c6897aa86e38e7 Mon Sep 17 00:00:00 2001
From: Alain Schlesser <alain.schlesser@gmail.com>
Date: Mon, 29 Mar 2021 12:37:41 +0100
Subject: [PATCH] Add tests for exceptions

---
 tests/Exception/Cli/InvalidArgumentTest.php   |  2 +-
 tests/Exception/Cli/InvalidColorTest.php      |  2 +-
 .../Exception/Cli/InvalidColumnFormatTest.php |  2 +-
 tests/Exception/Cli/InvalidCommandTest.php    |  2 +-
 tests/Exception/Cli/InvalidOptionTest.php     |  2 +-
 tests/Exception/Cli/InvalidSapiTest.php       |  2 +-
 tests/Exception/Cli/MissingArgumentTest.php   |  2 +-
 tests/Exception/InvalidAttributeNameTest.php  | 26 ++++++++++++
 tests/Exception/InvalidCssNameTest.php        | 26 ++++++++++++
 tests/Exception/InvalidExtensionTest.php      | 26 ++++++++++++
 tests/Exception/InvalidFormatTest.php         | 26 ++++++++++++
 tests/Exception/InvalidListNameTest.php       | 41 +++++++++++++++++++
 tests/Exception/InvalidSpecNameTest.php       | 26 ++++++++++++
 tests/Exception/InvalidSpecRuleNameTest.php   | 26 ++++++++++++
 tests/Exception/InvalidTagIdTest.php          | 26 ++++++++++++
 15 files changed, 230 insertions(+), 7 deletions(-)
 create mode 100644 tests/Exception/InvalidAttributeNameTest.php
 create mode 100644 tests/Exception/InvalidCssNameTest.php
 create mode 100644 tests/Exception/InvalidExtensionTest.php
 create mode 100644 tests/Exception/InvalidFormatTest.php
 create mode 100644 tests/Exception/InvalidListNameTest.php
 create mode 100644 tests/Exception/InvalidSpecNameTest.php
 create mode 100644 tests/Exception/InvalidSpecRuleNameTest.php
 create mode 100644 tests/Exception/InvalidTagIdTest.php

diff --git a/tests/Exception/Cli/InvalidArgumentTest.php b/tests/Exception/Cli/InvalidArgumentTest.php
index f9900bc73..5d5d9204f 100644
--- a/tests/Exception/Cli/InvalidArgumentTest.php
+++ b/tests/Exception/Cli/InvalidArgumentTest.php
@@ -8,7 +8,7 @@
 /**
  * Test the InvalidArgument exception.
  *
- * @covers \AmpProject\Exception\InvalidArgument
+ * @covers \AmpProject\Exception\Cli\InvalidArgument
  * @package ampproject/amp-toolbox
  */
 class InvalidArgumentTest extends TestCase
diff --git a/tests/Exception/Cli/InvalidColorTest.php b/tests/Exception/Cli/InvalidColorTest.php
index 1a81b517b..9cae2b2bd 100644
--- a/tests/Exception/Cli/InvalidColorTest.php
+++ b/tests/Exception/Cli/InvalidColorTest.php
@@ -8,7 +8,7 @@
 /**
  * Test the InvalidColor exception.
  *
- * @covers \AmpProject\Exception\InvalidColor
+ * @covers \AmpProject\Exception\Cli\InvalidColor
  * @package ampproject/amp-toolbox
  */
 class InvalidColorTest extends TestCase
diff --git a/tests/Exception/Cli/InvalidColumnFormatTest.php b/tests/Exception/Cli/InvalidColumnFormatTest.php
index 354dd33a1..7b26ca133 100644
--- a/tests/Exception/Cli/InvalidColumnFormatTest.php
+++ b/tests/Exception/Cli/InvalidColumnFormatTest.php
@@ -8,7 +8,7 @@
 /**
  * Test the InvalidColumnFormat exception.
  *
- * @covers \AmpProject\Exception\InvalidColumnFormat
+ * @covers \AmpProject\Exception\Cli\InvalidColumnFormat
  * @package ampproject/amp-toolbox
  */
 class InvalidColumnFormatTest extends TestCase
diff --git a/tests/Exception/Cli/InvalidCommandTest.php b/tests/Exception/Cli/InvalidCommandTest.php
index ec2693f06..fa4b21126 100644
--- a/tests/Exception/Cli/InvalidCommandTest.php
+++ b/tests/Exception/Cli/InvalidCommandTest.php
@@ -8,7 +8,7 @@
 /**
  * Test the InvalidCommand exception.
  *
- * @covers \AmpProject\Exception\InvalidCommand
+ * @covers \AmpProject\Exception\Cli\InvalidCommand
  * @package ampproject/amp-toolbox
  */
 class InvalidCommandTest extends TestCase
diff --git a/tests/Exception/Cli/InvalidOptionTest.php b/tests/Exception/Cli/InvalidOptionTest.php
index 55e00ab51..9b2a1be65 100644
--- a/tests/Exception/Cli/InvalidOptionTest.php
+++ b/tests/Exception/Cli/InvalidOptionTest.php
@@ -8,7 +8,7 @@
 /**
  * Test the InvalidOption exception.
  *
- * @covers \AmpProject\Exception\InvalidOption
+ * @covers \AmpProject\Exception\Cli\InvalidOption
  * @package ampproject/amp-toolbox
  */
 class InvalidOptionTest extends TestCase
diff --git a/tests/Exception/Cli/InvalidSapiTest.php b/tests/Exception/Cli/InvalidSapiTest.php
index 132990ff1..4455fa469 100644
--- a/tests/Exception/Cli/InvalidSapiTest.php
+++ b/tests/Exception/Cli/InvalidSapiTest.php
@@ -8,7 +8,7 @@
 /**
  * Test the InvalidSapi exception.
  *
- * @covers \AmpProject\Exception\InvalidSapi
+ * @covers \AmpProject\Exception\Cli\InvalidSapi
  * @package ampproject/amp-toolbox
  */
 class InvalidSapiTest extends TestCase
diff --git a/tests/Exception/Cli/MissingArgumentTest.php b/tests/Exception/Cli/MissingArgumentTest.php
index 64fcaf662..daf3855c9 100644
--- a/tests/Exception/Cli/MissingArgumentTest.php
+++ b/tests/Exception/Cli/MissingArgumentTest.php
@@ -8,7 +8,7 @@
 /**
  * Test the MissingArgument exception.
  *
- * @covers \AmpProject\Exception\MissingArgument
+ * @covers \AmpProject\Exception\Cli\MissingArgument
  * @package ampproject/amp-toolbox
  */
 class MissingArgumentTest extends TestCase
diff --git a/tests/Exception/InvalidAttributeNameTest.php b/tests/Exception/InvalidAttributeNameTest.php
new file mode 100644
index 000000000..b9d45bc65
--- /dev/null
+++ b/tests/Exception/InvalidAttributeNameTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidAttributeName exception.
+ *
+ * @covers \AmpProject\Exception\InvalidAttributeName
+ * @package ampproject/amp-toolbox
+ */
+class InvalidAttributeNameTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for an attribute.
+     */
+    public function testThrowingForAttribute()
+    {
+        $this->expectException(InvalidAttributeName::class);
+        $this->expectExceptionMessage("Invalid attribute 'attributeName' was requested from the validator spec.");
+
+        throw InvalidAttributeName::forAttribute('attributeName');
+    }
+}
diff --git a/tests/Exception/InvalidCssNameTest.php b/tests/Exception/InvalidCssNameTest.php
new file mode 100644
index 000000000..23d8c07c2
--- /dev/null
+++ b/tests/Exception/InvalidCssNameTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidCssName exception.
+ *
+ * @covers \AmpProject\Exception\InvalidCssName
+ * @package ampproject/amp-toolbox
+ */
+class InvalidCssNameTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for a CSS name.
+     */
+    public function testThrowingForCssName()
+    {
+        $this->expectException(InvalidCssName::class);
+        $this->expectExceptionMessage("Invalid css name 'cssName' was requested from the validator spec.");
+
+        throw InvalidCssName::forCssName('cssName');
+    }
+}
diff --git a/tests/Exception/InvalidExtensionTest.php b/tests/Exception/InvalidExtensionTest.php
new file mode 100644
index 000000000..8bf571633
--- /dev/null
+++ b/tests/Exception/InvalidExtensionTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidExtension exception.
+ *
+ * @covers \AmpProject\Exception\InvalidExtension
+ * @package ampproject/amp-toolbox
+ */
+class InvalidExtensionTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for an extension.
+     */
+    public function testThrowingForExtension()
+    {
+        $this->expectException(InvalidExtension::class);
+        $this->expectExceptionMessage("Invalid extension 'extensionName' was requested from the validator spec.");
+
+        throw InvalidExtension::forExtension('extensionName');
+    }
+}
diff --git a/tests/Exception/InvalidFormatTest.php b/tests/Exception/InvalidFormatTest.php
new file mode 100644
index 000000000..4d8fede74
--- /dev/null
+++ b/tests/Exception/InvalidFormatTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidFormat exception.
+ *
+ * @covers \AmpProject\Exception\InvalidFormat
+ * @package ampproject/amp-toolbox
+ */
+class InvalidFormatTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for an format.
+     */
+    public function testThrowingForFormat()
+    {
+        $this->expectException(InvalidFormat::class);
+        $this->expectExceptionMessage("Invalid format 'formatName' was requested from the validator spec.");
+
+        throw InvalidFormat::forFormat('formatName');
+    }
+}
diff --git a/tests/Exception/InvalidListNameTest.php b/tests/Exception/InvalidListNameTest.php
new file mode 100644
index 000000000..c5f662bb9
--- /dev/null
+++ b/tests/Exception/InvalidListNameTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidListName exception.
+ *
+ * @covers \AmpProject\Exception\InvalidListName
+ * @package ampproject/amp-toolbox
+ */
+class InvalidListNameTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for an attribute list.
+     */
+    public function testThrowingForAttributeList()
+    {
+        $this->expectException(InvalidListName::class);
+        $this->expectExceptionMessage(
+            "Invalid attribute list 'attributeListName' was requested from the validator spec."
+        );
+
+        throw InvalidListName::forAttributeList('attributeListName');
+    }
+
+    /**
+     * Test throwing the exception for an declaration list.
+     */
+    public function testThrowingForDeclarationList()
+    {
+        $this->expectException(InvalidListName::class);
+        $this->expectExceptionMessage(
+            "Invalid declaration list 'declarationListName' was requested from the validator spec."
+        );
+
+        throw InvalidListName::forDeclarationList('declarationListName');
+    }
+}
diff --git a/tests/Exception/InvalidSpecNameTest.php b/tests/Exception/InvalidSpecNameTest.php
new file mode 100644
index 000000000..84dab60fd
--- /dev/null
+++ b/tests/Exception/InvalidSpecNameTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidSpecName exception.
+ *
+ * @covers \AmpProject\Exception\InvalidSpecName
+ * @package ampproject/amp-toolbox
+ */
+class InvalidSpecNameTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for a spec name.
+     */
+    public function testThrowingForSpecName()
+    {
+        $this->expectException(InvalidSpecName::class);
+        $this->expectExceptionMessage("Invalid spec name 'specName' was requested from the validator spec.");
+
+        throw InvalidSpecName::forSpecName('specName');
+    }
+}
diff --git a/tests/Exception/InvalidSpecRuleNameTest.php b/tests/Exception/InvalidSpecRuleNameTest.php
new file mode 100644
index 000000000..fa111b0bd
--- /dev/null
+++ b/tests/Exception/InvalidSpecRuleNameTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidSpecRuleName exception.
+ *
+ * @covers \AmpProject\Exception\InvalidSpecRuleName
+ * @package ampproject/amp-toolbox
+ */
+class InvalidSpecRuleNameTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for a spec rule name.
+     */
+    public function testThrowingForSpecRuleName()
+    {
+        $this->expectException(InvalidSpecRuleName::class);
+        $this->expectExceptionMessage("Invalid spec rule name 'specRuleName' was requested from the validator spec.");
+
+        throw InvalidSpecRuleName::forSpecRuleName('specRuleName');
+    }
+}
diff --git a/tests/Exception/InvalidTagIdTest.php b/tests/Exception/InvalidTagIdTest.php
new file mode 100644
index 000000000..cea7a0e74
--- /dev/null
+++ b/tests/Exception/InvalidTagIdTest.php
@@ -0,0 +1,26 @@
+<?php
+
+namespace AmpProject\Exception;
+
+use AmpProject\Tests\TestCase;
+
+/**
+ * Test the InvalidTagId exception.
+ *
+ * @covers \AmpProject\Exception\InvalidTagId
+ * @package ampproject/amp-toolbox
+ */
+class InvalidTagIdTest extends TestCase
+{
+
+    /**
+     * Test throwing the exception for a tag ID.
+     */
+    public function testThrowingForTagId()
+    {
+        $this->expectException(InvalidTagId::class);
+        $this->expectExceptionMessage("Invalid tag ID 'tagId' was requested from the validator tag.");
+
+        throw InvalidTagId::forTagId('tagId');
+    }
+}