Quellcode durchsuchen

Add test for overwriting behaviour

shalvah vor 5 Jahren
Ursprung
Commit
009389943c
2 geänderte Dateien mit 27 neuen und 3 gelöschten Zeilen
  1. 27 0
      tests/GenerateDocumentationTest.php
  2. 0 3
      todo.md

+ 27 - 0
tests/GenerateDocumentationTest.php

@@ -389,4 +389,31 @@ class GenerateDocumentationTest extends TestCase
         $this->assertFileExists(__DIR__ . '/../resources/docs/groups/2-group-2.md');
         $this->assertFileExists(__DIR__ . '/../resources/docs/groups/10-group-10.md');
     }
+
+    /** @test */
+    public function will_not_overwrite_modified_markdown_file_unless_force_option_is_set()
+    {
+        RouteFacade::get('/api/action1', TestGroupController::class . '@action1');
+        RouteFacade::get('/api/action1b', TestGroupController::class . '@action1b');
+        RouteFacade::get('/api/action2', TestGroupController::class . '@action2');
+
+        config(['scribe.routes.0.prefixes' => ['api/*']]);
+
+        $this->artisan('scribe:generate');
+
+        $file1MtimeAfterFirstGeneration = filemtime(__DIR__ . '/../resources/docs/groups/1-group-1.md');
+        $file2MtimeAfterFirstGeneration = filemtime(__DIR__ . '/../resources/docs/groups/2-group-2.md');
+
+        sleep(1);
+        touch(__DIR__ . '/../resources/docs/groups/1-group-1.md');
+        $file1MtimeAfterManualModification = filemtime(__DIR__ . '/../resources/docs/groups/1-group-1.md');
+        $this->assertGreaterThan($file1MtimeAfterFirstGeneration, $file1MtimeAfterManualModification);
+
+        $this->artisan('scribe:generate');
+
+        $file1MtimeAfterSecondGeneration = filemtime(__DIR__ . '/../resources/docs/groups/1-group-1.md');
+        $file2MtimeAfterSecondGeneration = filemtime(__DIR__ . '/../resources/docs/groups/2-group-2.md');
+        $this->assertEquals($file1MtimeAfterManualModification, $file1MtimeAfterSecondGeneration);
+        $this->assertNotEquals($file2MtimeAfterFirstGeneration, $file2MtimeAfterSecondGeneration);
+    }
 }

+ 0 - 3
todo.md

@@ -16,6 +16,3 @@
 - Command scribe:strategy: It would be nice if we had a make strategy command that can help people generate custom strategies
 - Possible feature: https://github.com/mpociot/laravel-apidoc-generator/issues/731
 
-# Tests
-- Add tests that verify the overwriting behaviour of the command when --force is used
-