diff --git a/composer.json b/composer.json
index bac01dc..e94c79b 100644
--- a/composer.json
+++ b/composer.json
@@ -32,7 +32,8 @@
"scrivo/highlight.php": "^9.0"
},
"require-dev": {
- "phpunit/phpunit": "^8.5"
+ "phpunit/phpunit": "^8.5",
+ "spatie/phpunit-snapshot-assertions": "^3.0 || ^4.0"
},
"repositories": [
{
diff --git a/tests/commands/ApiControllerTest.php b/tests/commands/ApiControllerTest.php
index 57dc314..2c90d6d 100644
--- a/tests/commands/ApiControllerTest.php
+++ b/tests/commands/ApiControllerTest.php
@@ -1,4 +1,5 @@
generateApi(Yii::getAlias('@yiiunit/apidoc/data/api'), '@runtime', ['template' => 'bootstrap']);
+ $sourceFilesDir = Yii::getAlias('@yiiunit/apidoc/data/api');
+ $output = $this->generateApi($sourceFilesDir, '@runtime', ['template' => 'bootstrap']);
$this->assertNotEmpty($output);
$this->assertStringContainsString('generating search index...done.', $output);
+ $filesCount = 0;
$outputPath = Yii::getAlias('@runtime');
- // Class `Animal` :
- $animalFile = $outputPath . DIRECTORY_SEPARATOR . 'yiiunit-apidoc-data-api-animal-animal.html';
- $this->assertTrue(file_exists($animalFile));
- $animalContent = file_get_contents($animalFile);
- $this->assertStringContainsString('
Abstract Class yiiunit\apidoc\data\api\animal\Animal ', $animalContent);
- $this->assertStringContainsString('Available since version 1.0 ', $animalContent);
- $this->assertStringContainsString('Animal is a base class for animals.', $animalContent);
- $this->assertContainsWithoutIndent(
- <<
- public integer getSomething ( \$test )
-
-
-
- \$test
-
-
-
-
- return
- integer
-
-
-HTML
- , $animalContent
- );
- $this->assertContainsWithoutIndent(
- <<
- \$name
- string
- Animal name.
- yiiunit\apidoc\data\api\animal\Animal
-
-HTML
- , $animalContent
- );
- $this->assertContainsWithoutIndent(
- <<
- \$birthDate
- integer
- Animal birth date as a UNIX timestamp.
- yiiunit\apidoc\data\api\animal\Animal
-
-HTML
- , $animalContent
- );
- $this->assertContainsWithoutIndent(
- <<
-getAge()
-Returns animal age in seconds.
-yiiunit\apidoc\data\api\animal\Animal
-
-HTML
- , $animalContent
- );
- $this->assertContainsWithoutIndent(
- <<
- render()
- Renders animal description.
- yiiunit\apidoc\data\api\animal\Animal
-
-HTML
- , $animalContent
- );
-
- $this->assertContainsWithoutIndent(
- <<
- isOlder()
- Checks whether the animal is older than the specified time.
- yiiunit\apidoc\data\api\animal\Animal
-
-HTML
- , $animalContent
- );
-
- $this->assertContainsWithoutIndent(
- <<public boolean isOlder ( \$date )
-
- \$date
- integer
-
- Date as a UNIX timestamp.
-
-
-HTML
- , $animalContent
- );
-
- // Class `Dog` :
- $dogFile = $outputPath . DIRECTORY_SEPARATOR . 'yiiunit-apidoc-data-api-animal-dog.html';
- $this->assertTrue(file_exists($dogFile));
- $dogContent = file_get_contents($dogFile);
- $this->assertStringContainsString('Available since version 1.1 ', $dogContent);
- $this->assertStringNotContainsString('@inheritdoc', $dogContent);
-
- // Class `Cat` :
- $catFile = $outputPath . DIRECTORY_SEPARATOR . 'yiiunit-apidoc-data-api-animal-cat.html';
- $this->assertTrue(file_exists($catFile));
- $catContent = file_get_contents($catFile);
- $this->assertStringNotContainsString('@inheritdoc', $catContent);
+ foreach (glob("{$outputPath}/yiiunit-apidoc-data-api*") as $filePath) {
+ $fileContent = file_get_contents($filePath);
+
+ // Deleting dynamic content
+ $fileContent = preg_replace('/.*?<\/p>/is', '', $fileContent);
+ $fileContent = preg_replace('/
+
+
+
+
+
+
+
+
+
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html
new file mode 100644
index 0000000..47dcfbb
--- /dev/null
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__2.html
@@ -0,0 +1,500 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ Cat, yiiunit\apidoc\data\api\animal\Cat - Yii Framework 2.0 API Documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
Class yiiunit\apidoc\data\api\animal\Cat
+
+
+
+
+
+
Cat represents a cat animal.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Method Details
+
+
+
Hide inherited methods
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source code
+
+
+
+
+
+ public function getAge ()
+ {
+ return time() - $this ->birthDate;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source code
+
+
+
+
+
+ public function isOlder ($date)
+ {
+ return $this ->getAge() > $date;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
Renders animal description.
+
+
+
+
+
+
+
+
+
+ Source code
+
+
+
+
+
+ public function render ()
+ {
+
+ return 'This is a cat' ;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html
new file mode 100644
index 0000000..76141f0
--- /dev/null
+++ b/tests/commands/__snapshots__/ApiControllerTest__testGenerateBootstrap__3.html
@@ -0,0 +1,500 @@
+
+
+
+
+
+
+
+
+
+
+
+
+ Dog, yiiunit\apidoc\data\api\animal\Dog - Yii Framework 2.0 API Documentation
+
+
+
+
+
+
+
+
+
+
+
+
+
Class yiiunit\apidoc\data\api\animal\Dog
+
+
+
+
+
+
Dog represents a dog animal.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Method Details
+
+
+
Hide inherited methods
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source code
+
+
+
+
+
+ public function getAge ()
+ {
+ return time() - $this ->birthDate;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Source code
+
+
+
+
+
+ public function isOlder ($date)
+ {
+ return $this ->getAge() > $date;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
Renders animal description.
+
+
+
+
+
+
+
+
+
+ Source code
+
+
+
+
+
+ public function render ()
+ {
+
+ return 'This is a dog' ;
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+