From 33c1f8d7a53b0e41830638b53afbe9bb5a8326c0 Mon Sep 17 00:00:00 2001 From: everzet Date: Wed, 7 Jan 2015 20:43:07 +0000 Subject: [PATCH 01/37] Shorten feature names to make them less noisy --- ...release.feature => behat_documentation_is_published.feature} | 2 +- ...blishing.feature => documentation_meta_is_generated.feature} | 2 +- ...ase.feature => extension_documentation_is_published.feature} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename features/{documentation_is_published_on_repository_release.feature => behat_documentation_is_published.feature} (95%) rename features/{documentation_meta_is_generated_after_publishing.feature => documentation_meta_is_generated.feature} (95%) rename features/{extension_documentation_is_published_on_its_release.feature => extension_documentation_is_published.feature} (95%) diff --git a/features/documentation_is_published_on_repository_release.feature b/features/behat_documentation_is_published.feature similarity index 95% rename from features/documentation_is_published_on_repository_release.feature rename to features/behat_documentation_is_published.feature index 3ee1214..ca05f28 100644 --- a/features/documentation_is_published_on_repository_release.feature +++ b/features/behat_documentation_is_published.feature @@ -1,4 +1,4 @@ -Feature: Documentation is published on repository release +Feature: Behat documentation is published In order to help newcomers start using behat quicker As a documentation contributor I want behat documentation to be published after we release a new version of it diff --git a/features/documentation_meta_is_generated_after_publishing.feature b/features/documentation_meta_is_generated.feature similarity index 95% rename from features/documentation_meta_is_generated_after_publishing.feature rename to features/documentation_meta_is_generated.feature index db0df26..ecd6944 100644 --- a/features/documentation_meta_is_generated_after_publishing.feature +++ b/features/documentation_meta_is_generated.feature @@ -1,4 +1,4 @@ -Feature: Documentation meta is generated after publishing +Feature: Documentation meta is generated In order to help users find relevant information quicker As a documentation contributor I want documentation meta to be available after publishing diff --git a/features/extension_documentation_is_published_on_its_release.feature b/features/extension_documentation_is_published.feature similarity index 95% rename from features/extension_documentation_is_published_on_its_release.feature rename to features/extension_documentation_is_published.feature index 12e7ff6..20149e4 100644 --- a/features/extension_documentation_is_published_on_its_release.feature +++ b/features/extension_documentation_is_published.feature @@ -1,4 +1,4 @@ -Feature: Extension documentation is published on it's release +Feature: Extension documentation is published In order to help newcomers start extending behat quicker As a documentation contributor I want extensions documentation to be published after contributors release a new versions of them From bb5158424657fa349c8858c910d54d9b9fb1b18b Mon Sep 17 00:00:00 2001 From: everzet Date: Wed, 7 Jan 2015 20:57:07 +0000 Subject: [PATCH 02/37] Describe current documentation feature --- ...current_documentation_is_available.feature | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 features/current_documentation_is_available.feature diff --git a/features/current_documentation_is_available.feature b/features/current_documentation_is_available.feature new file mode 100644 index 0000000..e8d756c --- /dev/null +++ b/features/current_documentation_is_available.feature @@ -0,0 +1,34 @@ +Feature: Current documentation is available + In order to help newcomers not get lost in multiple versions of the framework + As a documentation contributor + I want latest most stable version of documentation to be available as current + + Rules: + - Use the latest stable release (v2.0.1) if there are some + - If there are no stable releases, but there are some dev releases (v2.0.x) - use the latest + - If there are no stable or dev releases, then use branches in this order: master, develop + + Scenario: Having some stable versions published + Given "behat/symfony2-extension" version "v2.0.0" was documented in "Behat/Symfony2Extension" + And "behat/symfony2-extension" version "master" was documented in "Behat/Symfony2Extension" + And "behat/symfony2-extension" version "v1.1.2" was documented in "Behat/Symfony2Extension" + When I release "Behat/Symfony2Extension" version "v2.0.0" + And I release "Behat/Symfony2Extension" version "master" + And I release "Behat/Symfony2Extension" version "v1.1.2" + Then current "behat/symfony2-extension" documentation should point to version "v2.0.0" + + Scenario: Having dev versions published + Given "behat/behat" version "v3.0" was documented in "Behat/docs" + And "behat/behat" version "master" was documented in "Behat/docs" + And "behat/behat" version "v2.5" was documented in "Behat/docs" + When I release "Behat/docs" version "v2.5" + And I release "Behat/docs" version "v3.0" + And I release "Behat/docs" version "master" + Then current "behat/behat" documentation should point to version "v3.0.x" + + Scenario: Having only branch versions published + Given "behat/behat" version "master" was documented in "Behat/docs" + And "behat/behat" version "develop" was documented in "Behat/docs" + When I release "Behat/docs" version "master" + And I release "Behat/docs" version "develop" + Then current "behat/behat" documentation should point to version "develop" From be271f12b73231f2b2e18f9aa208562e624d1dc3 Mon Sep 17 00:00:00 2001 From: everzet Date: Wed, 7 Jan 2015 21:03:25 +0000 Subject: [PATCH 03/37] Write missing step definition for current documentation --- .../bootstrap/DocumentationContributorContext.php | 12 ++++++++++++ features/current_documentation_is_available.feature | 6 +++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index a4a0ca7..fa0f3eb 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -138,6 +138,18 @@ public function timeOfPageShouldBe(PageId $pageId, $project, $versionString, Dat PHPUnit::assertEquals($time, $page->getDocumentationTime()); } + /** + * @Then current version of :project documentation should point to version :versionString + */ + public function currentVersionOfDocumentationShouldPointToVersion($project, $versionString) + { + $documentationId = new ProjectDocumentationId($project, 'current'); + $page = $this->documentationManager->findPage($documentationId, new PageId('index.html')); + + PHPUnit::assertNotNull($page, 'Page not found.'); + PHPUnit::assertEquals($versionString, $page->getVersionString()); + } + /** * @Then documentation for :versionString should be in the list of available documentation for :project */ diff --git a/features/current_documentation_is_available.feature b/features/current_documentation_is_available.feature index e8d756c..840d985 100644 --- a/features/current_documentation_is_available.feature +++ b/features/current_documentation_is_available.feature @@ -15,7 +15,7 @@ Feature: Current documentation is available When I release "Behat/Symfony2Extension" version "v2.0.0" And I release "Behat/Symfony2Extension" version "master" And I release "Behat/Symfony2Extension" version "v1.1.2" - Then current "behat/symfony2-extension" documentation should point to version "v2.0.0" + Then current version of "behat/symfony2-extension" documentation should point to version "v2.0.0" Scenario: Having dev versions published Given "behat/behat" version "v3.0" was documented in "Behat/docs" @@ -24,11 +24,11 @@ Feature: Current documentation is available When I release "Behat/docs" version "v2.5" And I release "Behat/docs" version "v3.0" And I release "Behat/docs" version "master" - Then current "behat/behat" documentation should point to version "v3.0.x" + Then current version of "behat/behat" documentation should point to version "v3.0.x" Scenario: Having only branch versions published Given "behat/behat" version "master" was documented in "Behat/docs" And "behat/behat" version "develop" was documented in "Behat/docs" When I release "Behat/docs" version "master" And I release "Behat/docs" version "develop" - Then current "behat/behat" documentation should point to version "develop" + Then current version of "behat/behat" documentation should point to version "develop" From 762d645777f7dcb139295ad885f744245e564525 Mon Sep 17 00:00:00 2001 From: everzet Date: Wed, 7 Jan 2015 21:15:52 +0000 Subject: [PATCH 04/37] Introduce DocumentationRepository interface This interface will magnet most of the storing functionality from the Publisher, leaving it only with logical `publish()`. The reason is very simple - I want to have separate control over querying of publishing documentation meta and actually publishing it. --- .../Repository/DocumentationRepository.php | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/Documentation/Repository/DocumentationRepository.php diff --git a/src/Documentation/Repository/DocumentationRepository.php b/src/Documentation/Repository/DocumentationRepository.php new file mode 100644 index 0000000..e977dbb --- /dev/null +++ b/src/Documentation/Repository/DocumentationRepository.php @@ -0,0 +1,27 @@ + Date: Wed, 7 Jan 2015 21:33:12 +0000 Subject: [PATCH 05/37] Shorten DocumentationRepository to Repository --- .../Repository/{DocumentationRepository.php => Repository.php} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename src/Documentation/Repository/{DocumentationRepository.php => Repository.php} (94%) diff --git a/src/Documentation/Repository/DocumentationRepository.php b/src/Documentation/Repository/Repository.php similarity index 94% rename from src/Documentation/Repository/DocumentationRepository.php rename to src/Documentation/Repository/Repository.php index e977dbb..08b5929 100644 --- a/src/Documentation/Repository/DocumentationRepository.php +++ b/src/Documentation/Repository/Repository.php @@ -7,7 +7,7 @@ /** * Stores published documentation. */ -interface DocumentationRepository +interface Repository { /** * Saves published documentation to the repository. From 95efabc4576cd283b16d24bab83f0aace0cae714 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 13:55:18 +0000 Subject: [PATCH 06/37] Move fakes into tests namespace --- .../bootstrap/DocumentationContributorContext.php | 14 +++++++------- .../bootstrap/DocumentationTransformations.php | 4 ++-- .../Fake/Documentation/DocumentedDownload.php | 2 +- .../Fake/Documentation/FakeBuilder.php | 2 +- .../Fake/Documentation/FakeBuiltDocumentation.php | 2 +- .../Fake/Documentation/FakeDocumentedDownload.php | 6 +++--- .../Fake/Documentation/FakePublisher.php | 2 +- .../Fake/Documentation/FakeSource.php | 2 +- .../Fake/Documentation/FakeSourceFinder.php | 2 +- .../Fake/Documentation/build/index.html | 0 .../Fake/Package/FakePackage.php | 2 +- .../Fake/Package/FakePackageFinder.php | 2 +- .../Fake/Package/PackagedDownload.php | 2 +- .../Fake/Release/FakeDownload.php | 2 +- .../Fake/Release/FakeDownloader.php | 2 +- .../Fake/Release/FakeRepository.php | 2 +- 16 files changed, 24 insertions(+), 24 deletions(-) rename {features/bootstrap => tests}/Fake/Documentation/DocumentedDownload.php (74%) rename {features/bootstrap => tests}/Fake/Documentation/FakeBuilder.php (87%) rename {features/bootstrap => tests}/Fake/Documentation/FakeBuiltDocumentation.php (94%) rename {features/bootstrap => tests}/Fake/Documentation/FakeDocumentedDownload.php (89%) rename {features/bootstrap => tests}/Fake/Documentation/FakePublisher.php (96%) rename {features/bootstrap => tests}/Fake/Documentation/FakeSource.php (65%) rename {features/bootstrap => tests}/Fake/Documentation/FakeSourceFinder.php (88%) rename {features/bootstrap => tests}/Fake/Documentation/build/index.html (100%) rename {features/bootstrap => tests}/Fake/Package/FakePackage.php (94%) rename {features/bootstrap => tests}/Fake/Package/FakePackageFinder.php (89%) rename {features/bootstrap => tests}/Fake/Package/PackagedDownload.php (76%) rename {features/bootstrap => tests}/Fake/Release/FakeDownload.php (96%) rename {features/bootstrap => tests}/Fake/Release/FakeDownloader.php (93%) rename {features/bootstrap => tests}/Fake/Release/FakeRepository.php (94%) diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index fa0f3eb..256708a 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -14,13 +14,13 @@ use Behat\Borg\Release\Release; use Behat\Borg\Release\Version; use Behat\Borg\ReleaseManager; -use Fake\Documentation\FakeBuilder; -use Fake\Documentation\FakeDocumentedDownload; -use Fake\Documentation\FakePublisher; -use Fake\Documentation\FakeSource; -use Fake\Documentation\FakeSourceFinder; -use Fake\Package\FakePackageFinder; -use Fake\Release\FakeDownloader; +use tests\Behat\Borg\Fake\Documentation\FakeBuilder; +use tests\Behat\Borg\Fake\Documentation\FakeDocumentedDownload; +use tests\Behat\Borg\Fake\Documentation\FakePublisher; +use tests\Behat\Borg\Fake\Documentation\FakeSource; +use tests\Behat\Borg\Fake\Documentation\FakeSourceFinder; +use tests\Behat\Borg\Fake\Package\FakePackageFinder; +use tests\Behat\Borg\Fake\Release\FakeDownloader; use PHPUnit_Framework_Assert as PHPUnit; /** diff --git a/features/bootstrap/DocumentationTransformations.php b/features/bootstrap/DocumentationTransformations.php index 582c12d..8de1744 100644 --- a/features/bootstrap/DocumentationTransformations.php +++ b/features/bootstrap/DocumentationTransformations.php @@ -2,8 +2,8 @@ use Behat\Borg\Documentation\Page\PageId; use Behat\Borg\Release\Version; -use Fake\Package\FakePackage; -use Fake\Release\FakeRepository; +use tests\Behat\Borg\Fake\Package\FakePackage; +use tests\Behat\Borg\Fake\Release\FakeRepository; trait DocumentationTransformations { diff --git a/features/bootstrap/Fake/Documentation/DocumentedDownload.php b/tests/Fake/Documentation/DocumentedDownload.php similarity index 74% rename from features/bootstrap/Fake/Documentation/DocumentedDownload.php rename to tests/Fake/Documentation/DocumentedDownload.php index 82a6d93..112befe 100644 --- a/features/bootstrap/Fake/Documentation/DocumentedDownload.php +++ b/tests/Fake/Documentation/DocumentedDownload.php @@ -1,6 +1,6 @@ Date: Sun, 11 Jan 2015 14:28:29 +0000 Subject: [PATCH 07/37] Move Package\Documentation to PackageDocumentation All classes in PackageDocumentation have a sole purpose of linking two modules together. They naturally do not belong to any of these modules on their own. --- features/bootstrap/DocumentationContributorContext.php | 4 ++-- .../DocumentationPackageFinderSpec.php | 4 ++-- .../DocumentationPackageSpec.php | 2 +- .../PackagedDocumentationBuilderSpec.php} | 4 ++-- .../PackagedDocumentationIdSpec.php} | 4 ++-- .../Documentation => PackageDocumentation}/borg.json | 0 .../DocumentationBundle/Resources/config/services.xml | 4 ++-- .../DocumentationPackage.php | 2 +- .../DocumentationPackageFinder.php | 6 +++--- .../PackagedDocumentationBuilder.php} | 6 +++--- .../PackagedDocumentationId.php} | 6 +++--- 11 files changed, 21 insertions(+), 21 deletions(-) rename spec/{Package/Documentation => PackageDocumentation}/DocumentationPackageFinderSpec.php (89%) rename spec/{Package/Documentation => PackageDocumentation}/DocumentationPackageSpec.php (96%) rename spec/{Package/Documentation/PackageDocumentationBuilderSpec.php => PackageDocumentation/PackagedDocumentationBuilderSpec.php} (95%) rename spec/{Package/Documentation/PackageDocumentationIdSpec.php => PackageDocumentation/PackagedDocumentationIdSpec.php} (93%) rename spec/{Package/Documentation => PackageDocumentation}/borg.json (100%) rename src/{Package/Documentation => PackageDocumentation}/DocumentationPackage.php (95%) rename src/{Package/Documentation => PackageDocumentation}/DocumentationPackageFinder.php (72%) rename src/{Package/Documentation/PackageDocumentationBuilder.php => PackageDocumentation/PackagedDocumentationBuilder.php} (88%) rename src/{Package/Documentation/PackageDocumentationId.php => PackageDocumentation/PackagedDocumentationId.php} (85%) diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index 256708a..90ed219 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -7,7 +7,7 @@ use Behat\Borg\Documentation\Publisher\PublishedDocumentation; use Behat\Borg\Package\ReleasePackager; use Behat\Borg\Package\Package; -use Behat\Borg\Package\Documentation\PackageDocumentationBuilder; +use Behat\Borg\PackageDocumentation\PackagedDocumentationBuilder; use Behat\Borg\DocumentationManager; use Behat\Borg\Release\ReleaseDownloader; use Behat\Borg\Release\Repository; @@ -50,7 +50,7 @@ public function __construct() $releaseDownloader = new ReleaseDownloader($this->downloader); $releasePackager = new ReleasePackager($packageFinder); - $documentingBuilder = new PackageDocumentationBuilder($sourceFinder, $this->documentationManager); + $documentingBuilder = new PackagedDocumentationBuilder($sourceFinder, $this->documentationManager); $this->releaseManager->registerListener($releaseDownloader); $releaseDownloader->registerListener($releasePackager); diff --git a/spec/Package/Documentation/DocumentationPackageFinderSpec.php b/spec/PackageDocumentation/DocumentationPackageFinderSpec.php similarity index 89% rename from spec/Package/Documentation/DocumentationPackageFinderSpec.php rename to spec/PackageDocumentation/DocumentationPackageFinderSpec.php index 40bb9e6..790ff1f 100644 --- a/spec/Package/Documentation/DocumentationPackageFinderSpec.php +++ b/spec/PackageDocumentation/DocumentationPackageFinderSpec.php @@ -1,8 +1,8 @@ + class="Behat\Borg\PackageDocumentation\DocumentationPackageFinder" public="false"/> @@ -34,7 +34,7 @@ diff --git a/src/Package/Documentation/DocumentationPackage.php b/src/PackageDocumentation/DocumentationPackage.php similarity index 95% rename from src/Package/Documentation/DocumentationPackage.php rename to src/PackageDocumentation/DocumentationPackage.php index 5449fcd..6c2fbc7 100644 --- a/src/Package/Documentation/DocumentationPackage.php +++ b/src/PackageDocumentation/DocumentationPackage.php @@ -1,6 +1,6 @@ getVersion(); $time = $download->getReleaseTime(); - $anId = new PackageDocumentationId($package, $version); + $anId = new PackagedDocumentationId($package, $version); $this->manager->build(new Documentation($anId, $time, $source)); } diff --git a/src/Package/Documentation/PackageDocumentationId.php b/src/PackageDocumentation/PackagedDocumentationId.php similarity index 85% rename from src/Package/Documentation/PackageDocumentationId.php rename to src/PackageDocumentation/PackagedDocumentationId.php index f622ee0..4f86cdb 100644 --- a/src/Package/Documentation/PackageDocumentationId.php +++ b/src/PackageDocumentation/PackagedDocumentationId.php @@ -1,15 +1,15 @@ Date: Sun, 11 Jan 2015 14:42:02 +0000 Subject: [PATCH 08/37] Remove needless tests for integration objects They are already tested acceptance and integration tests - no need to waste resources on maintaining additional tests of the same logic. --- .../ComposerPackageFinderSpec.php | 32 --------- spec/ComposerPackage/composer.json | 3 - .../DocumentationPackageFinderSpec.php | 32 --------- .../PackagedDocumentationBuilderSpec.php | 66 ------------------- spec/PackageDocumentation/borg.json | 3 - 5 files changed, 136 deletions(-) delete mode 100644 spec/ComposerPackage/ComposerPackageFinderSpec.php delete mode 100644 spec/ComposerPackage/composer.json delete mode 100644 spec/PackageDocumentation/DocumentationPackageFinderSpec.php delete mode 100644 spec/PackageDocumentation/PackagedDocumentationBuilderSpec.php delete mode 100644 spec/PackageDocumentation/borg.json diff --git a/spec/ComposerPackage/ComposerPackageFinderSpec.php b/spec/ComposerPackage/ComposerPackageFinderSpec.php deleted file mode 100644 index 74a2c28..0000000 --- a/spec/ComposerPackage/ComposerPackageFinderSpec.php +++ /dev/null @@ -1,32 +0,0 @@ -shouldHaveType(PackageFinder::class); - } - - function it_finds_a_composer_package_if_download_has_a_composer_json(Download $download) - { - $download->hasFile('composer.json')->willReturn(true); - $download->getFilePath('composer.json')->willReturn(__DIR__ . '/composer.json'); - - $this->findPackage($download)->shouldBeLike(new ComposerPackage('behat/behat')); - } - - function it_finds_nothing_if_download_does_not_have_a_composer_json(Download $download) - { - $download->hasFile('composer.json')->willReturn(false); - - $this->findPackage($download)->shouldReturn(null); - } -} diff --git a/spec/ComposerPackage/composer.json b/spec/ComposerPackage/composer.json deleted file mode 100644 index 1378cfc..0000000 --- a/spec/ComposerPackage/composer.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "name": "behat/behat" -} diff --git a/spec/PackageDocumentation/DocumentationPackageFinderSpec.php b/spec/PackageDocumentation/DocumentationPackageFinderSpec.php deleted file mode 100644 index 790ff1f..0000000 --- a/spec/PackageDocumentation/DocumentationPackageFinderSpec.php +++ /dev/null @@ -1,32 +0,0 @@ -shouldHaveType(PackageFinder::class); - } - - function it_finds_a_borg_package_if_download_has_a_borg_json_file(Download $download) - { - $download->hasFile('borg.json')->willReturn(true); - $download->getFilePath('borg.json')->willReturn(__DIR__ . '/borg.json'); - - $this->findPackage($download)->shouldBeLike(new DocumentationPackage('behat/behat')); - } - - function it_finds_nothing_if_download_does_not_have_a_borg_json(Download $download) - { - $download->hasFile('borg.json')->willReturn(false); - - $this->findPackage($download)->shouldReturn(null); - } -} diff --git a/spec/PackageDocumentation/PackagedDocumentationBuilderSpec.php b/spec/PackageDocumentation/PackagedDocumentationBuilderSpec.php deleted file mode 100644 index d740a6b..0000000 --- a/spec/PackageDocumentation/PackagedDocumentationBuilderSpec.php +++ /dev/null @@ -1,66 +0,0 @@ -getWrappedObject(), $publisher->getWrappedObject()); - $this->beConstructedWith($finder, $manager); - } - - function it_is_a_package_listener() - { - $this->shouldHaveType(PackageListener::class); - } - - function it_builds_the_found_documentation_and_notifies_listeners( - Package $package, - Download $download, - SourceFinder $finder, - Source $source, - Builder $builder, - BuiltDocumentation $builtDocumentation - ) { - $packageDownload = new PackageDownload($package->getWrappedObject(), $download->getWrappedObject()); - $finder->findSource($download)->willReturn($source); - $download->getVersion()->willReturn(Version::string('v2.5')); - $download->getReleaseTime()->willReturn(new \DateTimeImmutable()); - - $builder->build(Argument::which('getSource', $source->getWrappedObject()))->willReturn( - $builtDocumentation - )->shouldBeCalled(); - - $this->packageWasDownloaded($packageDownload); - } - - function it_does_not_build_documentation_if_finder_does_not_find_any_source( - Package $package, - Download $download, - SourceFinder $finder, - SourceFinder $finder, - Builder $builder - ) { - $packageDownload = new PackageDownload($package->getWrappedObject(), $download->getWrappedObject()); - $finder->findSource($download)->willReturn(null); - - $builder->build(Argument::any())->shouldNotBeCalled(); - - $this->packageWasDownloaded($packageDownload); - } -} diff --git a/spec/PackageDocumentation/borg.json b/spec/PackageDocumentation/borg.json deleted file mode 100644 index 1682a39..0000000 --- a/spec/PackageDocumentation/borg.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "for-package": "behat/behat" -} From d0f6f1c0b496f55fca4721466cbe3ea066ec35ce Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 14:59:42 +0000 Subject: [PATCH 09/37] Rename Documentation to RawDocumentation --- ...{DocumentationSpec.php => RawDocumentationSpec.php} | 4 ++-- src/Documentation/Builder/Builder.php | 6 +++--- .../{Documentation.php => RawDocumentation.php} | 2 +- .../PackagedDocumentationBuilder.php | 4 ++-- src/SphinxDoc/SphinxBuilder.php | 6 +++--- tests/Fake/Documentation/FakeBuilder.php | 4 ++-- tests/Fake/Documentation/FakeBuiltDocumentation.php | 4 ++-- tests/SphinxDoc/SphinxBuilderTest.php | 10 +++++----- 8 files changed, 20 insertions(+), 20 deletions(-) rename spec/Documentation/{DocumentationSpec.php => RawDocumentationSpec.php} (89%) rename src/Documentation/{Documentation.php => RawDocumentation.php} (97%) diff --git a/spec/Documentation/DocumentationSpec.php b/spec/Documentation/RawDocumentationSpec.php similarity index 89% rename from spec/Documentation/DocumentationSpec.php rename to spec/Documentation/RawDocumentationSpec.php index a461fc1..803e591 100644 --- a/spec/Documentation/DocumentationSpec.php +++ b/spec/Documentation/RawDocumentationSpec.php @@ -2,7 +2,7 @@ namespace spec\Behat\Borg\Documentation; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Source; use Behat\Borg\Release\Downloader\Download; @@ -13,7 +13,7 @@ use PhpSpec\ObjectBehavior; use Prophecy\Argument; -class DocumentationSpec extends ObjectBehavior +class RawDocumentationSpec extends ObjectBehavior { function let(DocumentationId $anId, DateTimeImmutable $time, Source $source) { diff --git a/src/Documentation/Builder/Builder.php b/src/Documentation/Builder/Builder.php index 9c4e4fc..0cbddae 100644 --- a/src/Documentation/Builder/Builder.php +++ b/src/Documentation/Builder/Builder.php @@ -2,7 +2,7 @@ namespace Behat\Borg\Documentation\Builder; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\Exception\BuildFailed; /** @@ -13,11 +13,11 @@ interface Builder /** * Builds provided documentation. * - * @param Documentation $documentation + * @param RawDocumentation $documentation * * @return BuiltDocumentation * * @throws BuildFailed */ - public function build(Documentation $documentation); + public function build(RawDocumentation $documentation); } diff --git a/src/Documentation/Documentation.php b/src/Documentation/RawDocumentation.php similarity index 97% rename from src/Documentation/Documentation.php rename to src/Documentation/RawDocumentation.php index ac5f15b..d742d19 100644 --- a/src/Documentation/Documentation.php +++ b/src/Documentation/RawDocumentation.php @@ -7,7 +7,7 @@ /** * Represents raw, unprocessed documentation. */ -final class Documentation +final class RawDocumentation { private $anId; private $time; diff --git a/src/PackageDocumentation/PackagedDocumentationBuilder.php b/src/PackageDocumentation/PackagedDocumentationBuilder.php index 141013e..4db4dd6 100644 --- a/src/PackageDocumentation/PackagedDocumentationBuilder.php +++ b/src/PackageDocumentation/PackagedDocumentationBuilder.php @@ -2,7 +2,7 @@ namespace Behat\Borg\PackageDocumentation; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\Finder\SourceFinder; use Behat\Borg\DocumentationManager; use Behat\Borg\Package\Listener\PackageListener; @@ -52,6 +52,6 @@ public function packageWasDownloaded(PackageDownload $packageDownload) $time = $download->getReleaseTime(); $anId = new PackagedDocumentationId($package, $version); - $this->manager->build(new Documentation($anId, $time, $source)); + $this->manager->process(new RawDocumentation($anId, $time, $source)); } } diff --git a/src/SphinxDoc/SphinxBuilder.php b/src/SphinxDoc/SphinxBuilder.php index 48fc089..b0863af 100644 --- a/src/SphinxDoc/SphinxBuilder.php +++ b/src/SphinxDoc/SphinxBuilder.php @@ -3,7 +3,7 @@ namespace Behat\Borg\SphinxDoc; use Behat\Borg\Documentation\Builder\Builder; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Exception\BuildFailed; use Behat\Borg\Documentation\Exception\IncompatibleDocumentationGiven; @@ -39,7 +39,7 @@ public function __construct($buildPath, $configPath, Filesystem $filesystem) /** * {@inheritdoc} */ - public function build(Documentation $documentation) + public function build(RawDocumentation $documentation) { $source = $documentation->getSource(); @@ -63,7 +63,7 @@ public function build(Documentation $documentation) ); } - private function getWritableBuildPath(Documentation $documentation) + private function getWritableBuildPath(RawDocumentation $documentation) { $buildPath = $this->buildPath . '/' . $documentation->getId(); $this->filesystem->mkdir($buildPath); diff --git a/tests/Fake/Documentation/FakeBuilder.php b/tests/Fake/Documentation/FakeBuilder.php index 4326f06..aab3207 100644 --- a/tests/Fake/Documentation/FakeBuilder.php +++ b/tests/Fake/Documentation/FakeBuilder.php @@ -3,12 +3,12 @@ namespace tests\Behat\Borg\Fake\Documentation; use Behat\Borg\Documentation\Builder\Builder; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use DateTimeImmutable; final class FakeBuilder implements Builder { - public function build(Documentation $documentation) + public function build(RawDocumentation $documentation) { return new FakeBuiltDocumentation($documentation, new DateTimeImmutable()); } diff --git a/tests/Fake/Documentation/FakeBuiltDocumentation.php b/tests/Fake/Documentation/FakeBuiltDocumentation.php index 94b8de4..6f80289 100644 --- a/tests/Fake/Documentation/FakeBuiltDocumentation.php +++ b/tests/Fake/Documentation/FakeBuiltDocumentation.php @@ -3,7 +3,7 @@ namespace tests\Behat\Borg\Fake\Documentation; use Behat\Borg\Documentation\Builder\BuiltDocumentation; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use DateTimeImmutable; final class FakeBuiltDocumentation implements BuiltDocumentation @@ -11,7 +11,7 @@ final class FakeBuiltDocumentation implements BuiltDocumentation private $documentation; private $buildTime; - public function __construct(Documentation $documentation, DateTimeImmutable $buildTime) + public function __construct(RawDocumentation $documentation, DateTimeImmutable $buildTime) { $this->documentation = $documentation; $this->buildTime = $buildTime; diff --git a/tests/SphinxDoc/SphinxBuilderTest.php b/tests/SphinxDoc/SphinxBuilderTest.php index cc00ea2..6723700 100644 --- a/tests/SphinxDoc/SphinxBuilderTest.php +++ b/tests/SphinxDoc/SphinxBuilderTest.php @@ -2,7 +2,7 @@ namespace tests\Behat\Borg\SphinxDoc; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Source; use Behat\Borg\Release\Downloader\Download; @@ -38,7 +38,7 @@ function it_throws_an_exception_if_non_RST_documentation_provided() { $anId = $this->createDocumentationId('my/doc', '1.3'); $source = $this->createDocumentationSource(); - $documentation = new Documentation($anId, new DateTimeImmutable(), $source); + $documentation = new RawDocumentation($anId, new DateTimeImmutable(), $source); $this->builder->build($documentation); } @@ -48,7 +48,7 @@ function it_builds_RST_documentation_into_the_output_path() { $anId = $this->createDocumentationId('my/doc', 'v1.3'); $source = $this->createRstDocumentationSourceWithIndex("Docs\n===="); - $documentation = new Documentation($anId, new DateTimeImmutable(), $source); + $documentation = new RawDocumentation($anId, new DateTimeImmutable(), $source); $built = $this->builder->build($documentation); @@ -80,7 +80,7 @@ function it_builds_valid_template_when_doc_contains_Twig_like_content() $anId = $this->createDocumentationId('my/doc', 'v1.3'); $source = $this->createRstDocumentationSourceWithIndex($sourceContent); - $documentation = new Documentation($anId, new DateTimeImmutable(), $source); + $documentation = new RawDocumentation($anId, new DateTimeImmutable(), $source); $built = $this->builder->build($documentation); @@ -98,7 +98,7 @@ function it_throws_an_exception_if_sphinx_can_not_build_documents() { $anId = $this->createDocumentationId('my/doc', '1.3'); $source = $this->createRstDocumentationSourceWithoutIndex(); - $documentation = new Documentation($anId, new DateTimeImmutable(), $source); + $documentation = new RawDocumentation($anId, new DateTimeImmutable(), $source); $this->builder->build($documentation); } From efda1140945a6e2d79e165128df38d5d7a4a804f Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 14:59:52 +0000 Subject: [PATCH 10/37] Rename DocumentationManager::build() to DocumentationManager::process() --- spec/DocumentationManagerSpec.php | 8 ++++---- src/DocumentationManager.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/DocumentationManagerSpec.php b/spec/DocumentationManagerSpec.php index 63c6fb2..506e9be 100644 --- a/spec/DocumentationManagerSpec.php +++ b/spec/DocumentationManagerSpec.php @@ -4,7 +4,7 @@ use Behat\Borg\Documentation\Builder\Builder; use Behat\Borg\Documentation\Builder\BuiltDocumentation; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Page\PageId; use Behat\Borg\Documentation\Page\Page; @@ -21,21 +21,21 @@ function let(Builder $builder, Publisher $publisher) $this->beConstructedWith($builder, $publisher); } - function it_builds_documentation_using_builder_and_publishes_it_using_publisher( + function it_processes_documentation_using_builder_and_publishes_it_using_publisher( Builder $builder, DocumentationId $anId, Source $source, BuiltDocumentation $builtDocumentation, Publisher $publisher ) { - $documentation = new Documentation( + $documentation = new RawDocumentation( $anId->getWrappedObject(), new \DateTimeImmutable(), $source->getWrappedObject() ); $builder->build($documentation)->willReturn($builtDocumentation); $publisher->publish($builtDocumentation)->shouldBeCalled(); - $this->build($documentation); + $this->process($documentation); } function it_can_find_all_published_documentation_for_a_provided_project_name( diff --git a/src/DocumentationManager.php b/src/DocumentationManager.php index 0d84561..803ee94 100644 --- a/src/DocumentationManager.php +++ b/src/DocumentationManager.php @@ -3,7 +3,7 @@ namespace Behat\Borg; use Behat\Borg\Documentation\Builder\Builder; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Page\PageId; use Behat\Borg\Documentation\Page\Page; @@ -37,11 +37,11 @@ public function __construct(Builder $builder, Publisher $publisher) } /** - * Builds provided documentation. + * Processes raw documentation. * - * @param Documentation $documentation + * @param RawDocumentation $documentation */ - public function build(Documentation $documentation) + public function process(RawDocumentation $documentation) { $builtDocumentation = $this->builder->build($documentation); $this->publisher->publish($builtDocumentation); From 409684a8b4385fb87ab57d23e1f1ff9de02057b8 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 15:06:54 +0000 Subject: [PATCH 11/37] Introduce Repository into DocumentationManager --- spec/DocumentationManagerSpec.php | 20 ++++++++++++-------- src/Documentation/Publisher/Publisher.php | 2 ++ src/DocumentationManager.php | 20 ++++++++++++++------ 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/spec/DocumentationManagerSpec.php b/spec/DocumentationManagerSpec.php index 506e9be..d2aea9b 100644 --- a/spec/DocumentationManagerSpec.php +++ b/spec/DocumentationManagerSpec.php @@ -10,32 +10,36 @@ use Behat\Borg\Documentation\Page\Page; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; use Behat\Borg\Documentation\Publisher\Publisher; +use Behat\Borg\Documentation\Repository\Repository; use Behat\Borg\Documentation\Source; use PhpSpec\ObjectBehavior; use Prophecy\Argument; class DocumentationManagerSpec extends ObjectBehavior { - function let(Builder $builder, Publisher $publisher) + function let(Builder $builder, Publisher $publisher, Repository $repository) { - $this->beConstructedWith($builder, $publisher); + $this->beConstructedWith($builder, $publisher, $repository); } - function it_processes_documentation_using_builder_and_publishes_it_using_publisher( + function it_processes_documentation_by_building_publishing_and_then_saving_it_to_repository( Builder $builder, DocumentationId $anId, Source $source, BuiltDocumentation $builtDocumentation, - Publisher $publisher + Publisher $publisher, + Repository $repository ) { - $documentation = new RawDocumentation( + $raw = new RawDocumentation( $anId->getWrappedObject(), new \DateTimeImmutable(), $source->getWrappedObject() ); + $published = PublishedDocumentation::publish($builtDocumentation->getWrappedObject(), '/'); - $builder->build($documentation)->willReturn($builtDocumentation); - $publisher->publish($builtDocumentation)->shouldBeCalled(); + $builder->build($raw)->willReturn($builtDocumentation); + $publisher->publish($builtDocumentation)->willReturn($published); + $repository->save($published)->shouldBeCalled(); - $this->process($documentation); + $this->process($raw); } function it_can_find_all_published_documentation_for_a_provided_project_name( diff --git a/src/Documentation/Publisher/Publisher.php b/src/Documentation/Publisher/Publisher.php index 418a6e4..5183a84 100644 --- a/src/Documentation/Publisher/Publisher.php +++ b/src/Documentation/Publisher/Publisher.php @@ -15,6 +15,8 @@ interface Publisher * Publishes provided built documentation. * * @param BuiltDocumentation $builtDocumentation + * + * @return PublishedDocumentation */ public function publish(BuiltDocumentation $builtDocumentation); diff --git a/src/DocumentationManager.php b/src/DocumentationManager.php index 803ee94..ac2df1c 100644 --- a/src/DocumentationManager.php +++ b/src/DocumentationManager.php @@ -9,6 +9,7 @@ use Behat\Borg\Documentation\Page\Page; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; use Behat\Borg\Documentation\Publisher\Publisher; +use Behat\Borg\Documentation\Repository\Repository; /** * Manages documentation by providing high-level accessor methods. @@ -23,17 +24,23 @@ final class DocumentationManager * @var Publisher */ private $publisher; + /** + * @var Repository + */ + private $repository; /** * Initialize manager. * - * @param Builder $builder - * @param Publisher $publisher + * @param Builder $builder + * @param Publisher $publisher + * @param Repository $repository */ - public function __construct(Builder $builder, Publisher $publisher) + public function __construct(Builder $builder, Publisher $publisher, Repository $repository) { - $this->publisher = $publisher; $this->builder = $builder; + $this->publisher = $publisher; + $this->repository = $repository; } /** @@ -43,8 +50,9 @@ public function __construct(Builder $builder, Publisher $publisher) */ public function process(RawDocumentation $documentation) { - $builtDocumentation = $this->builder->build($documentation); - $this->publisher->publish($builtDocumentation); + $built = $this->builder->build($documentation); + $published = $this->publisher->publish($built); + $this->repository->save($published); } /** From 83c8f2298a8840f3b6789d4a7cf36920a038533c Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 15:28:21 +0000 Subject: [PATCH 12/37] Switch DocumentationManager to use repository --- spec/DocumentationManagerSpec.php | 54 ++++++++++----------- src/Documentation/Repository/Repository.php | 10 ++++ src/DocumentationManager.php | 5 +- 3 files changed, 39 insertions(+), 30 deletions(-) diff --git a/spec/DocumentationManagerSpec.php b/spec/DocumentationManagerSpec.php index d2aea9b..60bbf29 100644 --- a/spec/DocumentationManagerSpec.php +++ b/spec/DocumentationManagerSpec.php @@ -42,24 +42,8 @@ function it_processes_documentation_by_building_publishing_and_then_saving_it_to $this->process($raw); } - function it_can_find_all_published_documentation_for_a_provided_project_name( - DocumentationId $anId, - Publisher $publisher, - BuiltDocumentation $built - ) { - $built->getDocumentationId()->willReturn($anId); - $built->getBuildTime()->willReturn(new \DateTimeImmutable()); - $built->getDocumentationTime()->willReturn(new \DateTimeImmutable()); - - $publishedDocumentation = PublishedDocumentation::publish($built->getWrappedObject(), __DIR__); - - $publisher->findForProject('my/project')->willReturn([$publishedDocumentation]); - - $this->getAvailableDocumentation('my/project')->shouldReturn([$publishedDocumentation]); - } - - function it_locates_documentation_file_if_it_is_published_and_file_exists( - Publisher $publisher, + function it_finds_documentation_page_if_documentation_was_saved_and_has_asked_page( + Repository $repository, DocumentationId $anId, BuiltDocumentation $built ) { @@ -70,27 +54,26 @@ function it_locates_documentation_file_if_it_is_published_and_file_exists( $pageId = new PageId(basename(__FILE__)); $publishedDocumentation = PublishedDocumentation::publish($built->getWrappedObject(), __DIR__); - $publisher->hasPublished($anId)->willReturn(true); - $publisher->getPublished($anId)->willReturn($publishedDocumentation); + $repository->find($anId)->willReturn($publishedDocumentation); $page = $this->findPage($anId, $pageId); $page->shouldBeAnInstanceOf(Page::class); $page->getPath()->shouldReturn(__FILE__); } - function it_returns_null_if_documentation_was_not_published( - Publisher $publisher, + function it_finds_nothing_if_documentation_was_not_found( + Repository $repository, DocumentationId $anId ) { $pageId = new PageId(basename(__FILE__)); - $publisher->hasPublished($anId)->willReturn(false); + $repository->find($anId)->willReturn(null); $this->findPage($anId, $pageId)->shouldReturn(null); } - function it_returns_null_if_documentation_is_published_but_file_does_not_exist( - Publisher $publisher, + function it_finds_nothing_if_documentation_was_found_but_page_was_not( + Repository $repository, DocumentationId $anId, BuiltDocumentation $built ) { @@ -99,9 +82,26 @@ function it_returns_null_if_documentation_is_published_but_file_does_not_exist( $built->getWrappedObject(), __DIR__ ); - $publisher->hasPublished($anId)->willReturn(true); - $publisher->getPublished($anId)->willReturn($publishedDocumentation); + $repository->find($anId)->willReturn($publishedDocumentation); $this->findPage($anId, $pageId)->shouldReturn(null); } + + function it_finds_all_documentation_for_a_provided_project_name( + Repository $repository, + DocumentationId $anId, + BuiltDocumentation $built + ) { + $built->getDocumentationId()->willReturn($anId); + $built->getBuildTime()->willReturn(new \DateTimeImmutable()); + $built->getDocumentationTime()->willReturn(new \DateTimeImmutable()); + + $publishedDocumentation = PublishedDocumentation::publish( + $built->getWrappedObject(), __DIR__ + ); + + $repository->findForProject('my/project')->willReturn([$publishedDocumentation]); + + $this->getAvailableDocumentation('my/project')->shouldReturn([$publishedDocumentation]); + } } diff --git a/src/Documentation/Repository/Repository.php b/src/Documentation/Repository/Repository.php index 08b5929..cbcfd6c 100644 --- a/src/Documentation/Repository/Repository.php +++ b/src/Documentation/Repository/Repository.php @@ -2,6 +2,7 @@ namespace Behat\Borg\Documentation\Repository; +use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; /** @@ -16,6 +17,15 @@ interface Repository */ public function save(PublishedDocumentation $documentation); + /** + * Finds documentation by its id. + * + * @param DocumentationId $documentationId + * + * @return null|PublishedDocumentation + */ + public function find(DocumentationId $documentationId); + /** * Finds all documentation for particular project. * diff --git a/src/DocumentationManager.php b/src/DocumentationManager.php index ac2df1c..6a18feb 100644 --- a/src/DocumentationManager.php +++ b/src/DocumentationManager.php @@ -65,11 +65,10 @@ public function process(RawDocumentation $documentation) */ public function findPage(DocumentationId $documentationId, PageId $pageId) { - if (!$this->publisher->hasPublished($documentationId)) { + if (!$documentation = $this->repository->find($documentationId)) { return null; } - $documentation = $this->publisher->getPublished($documentationId); if (!$documentation->hasPage($pageId)) { return null; } @@ -86,6 +85,6 @@ public function findPage(DocumentationId $documentationId, PageId $pageId) */ public function getAvailableDocumentation($projectName) { - return $this->publisher->findForProject($projectName); + return $this->repository->findForProject($projectName); } } From 96dd07c8768307454f5855a2ebbc799cff5bbcd0 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 15:37:55 +0000 Subject: [PATCH 13/37] Introduce documentation Processor Move building, publishing and repository saving responsibilities behind the discrete interface. --- .../Processor/BuildingProcessorSpec.php | 48 +++++++++++++++++++ spec/DocumentationManagerSpec.php | 17 +++---- .../Processor/BuildingProcessor.php | 38 +++++++++++++++ src/Documentation/Processor/Processor.php | 18 +++++++ src/DocumentationManager.php | 23 +++------ 5 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 spec/Documentation/Processor/BuildingProcessorSpec.php create mode 100644 src/Documentation/Processor/BuildingProcessor.php create mode 100644 src/Documentation/Processor/Processor.php diff --git a/spec/Documentation/Processor/BuildingProcessorSpec.php b/spec/Documentation/Processor/BuildingProcessorSpec.php new file mode 100644 index 0000000..e0c5e16 --- /dev/null +++ b/spec/Documentation/Processor/BuildingProcessorSpec.php @@ -0,0 +1,48 @@ +beConstructedWith($builder, $publisher, $repository); + } + + function it_is_documentation_processor() + { + $this->shouldHaveType(Processor::class); + } + + function it_builds_publishes_and_saves_documentation_to_repository( + Builder $builder, + DocumentationId $anId, + Source $source, + BuiltDocumentation $builtDocumentation, + Publisher $publisher, + Repository $repository + ) { + $raw = new RawDocumentation( + $anId->getWrappedObject(), new \DateTimeImmutable(), $source->getWrappedObject() + ); + $published = PublishedDocumentation::publish($builtDocumentation->getWrappedObject(), '/'); + + $builder->build($raw)->willReturn($builtDocumentation); + $publisher->publish($builtDocumentation)->willReturn($published); + $repository->save($published)->shouldBeCalled(); + + $this->process($raw); + } +} diff --git a/spec/DocumentationManagerSpec.php b/spec/DocumentationManagerSpec.php index 60bbf29..b5ecf50 100644 --- a/spec/DocumentationManagerSpec.php +++ b/spec/DocumentationManagerSpec.php @@ -4,6 +4,7 @@ use Behat\Borg\Documentation\Builder\Builder; use Behat\Borg\Documentation\Builder\BuiltDocumentation; +use Behat\Borg\Documentation\Processor\Processor; use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Page\PageId; @@ -17,27 +18,21 @@ class DocumentationManagerSpec extends ObjectBehavior { - function let(Builder $builder, Publisher $publisher, Repository $repository) + function let(Processor $processor, Repository $repository) { - $this->beConstructedWith($builder, $publisher, $repository); + $this->beConstructedWith($processor, $repository); } - function it_processes_documentation_by_building_publishing_and_then_saving_it_to_repository( - Builder $builder, + function it_processes_documentation_using_processor( DocumentationId $anId, Source $source, - BuiltDocumentation $builtDocumentation, - Publisher $publisher, - Repository $repository + Processor $processor ) { $raw = new RawDocumentation( $anId->getWrappedObject(), new \DateTimeImmutable(), $source->getWrappedObject() ); - $published = PublishedDocumentation::publish($builtDocumentation->getWrappedObject(), '/'); - $builder->build($raw)->willReturn($builtDocumentation); - $publisher->publish($builtDocumentation)->willReturn($published); - $repository->save($published)->shouldBeCalled(); + $processor->process($raw)->shouldBeCalled(); $this->process($raw); } diff --git a/src/Documentation/Processor/BuildingProcessor.php b/src/Documentation/Processor/BuildingProcessor.php new file mode 100644 index 0000000..28f7d05 --- /dev/null +++ b/src/Documentation/Processor/BuildingProcessor.php @@ -0,0 +1,38 @@ +builder = $builder; + $this->publisher = $publisher; + $this->repository = $repository; + } + + /** + * {@inheritdoc} + */ + public function process(RawDocumentation $documentation) + { + $built = $this->builder->build($documentation); + $published = $this->publisher->publish($built); + $this->repository->save($published); + } +} diff --git a/src/Documentation/Processor/Processor.php b/src/Documentation/Processor/Processor.php new file mode 100644 index 0000000..4b5cc8b --- /dev/null +++ b/src/Documentation/Processor/Processor.php @@ -0,0 +1,18 @@ +builder = $builder; - $this->publisher = $publisher; + $this->processor = $processor; $this->repository = $repository; } @@ -50,9 +43,7 @@ public function __construct(Builder $builder, Publisher $publisher, Repository $ */ public function process(RawDocumentation $documentation) { - $built = $this->builder->build($documentation); - $published = $this->publisher->publish($built); - $this->repository->save($published); + $this->processor->process($documentation); } /** From 223a011dfdaecbc116e3d67f37853475f24cd7c4 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 15:48:24 +0000 Subject: [PATCH 14/37] Introduce PageFinder and move page finding repos to it --- .../Finder/RepositoryPageFinderSpec.php | 73 +++++++++++++++++++ spec/DocumentationManagerSpec.php | 44 ++--------- src/Documentation/Finder/PageFinder.php | 23 ++++++ .../Finder/RepositoryPageFinder.php | 44 +++++++++++ src/DocumentationManager.php | 21 +++--- 5 files changed, 158 insertions(+), 47 deletions(-) create mode 100644 spec/Documentation/Finder/RepositoryPageFinderSpec.php create mode 100644 src/Documentation/Finder/PageFinder.php create mode 100644 src/Documentation/Finder/RepositoryPageFinder.php diff --git a/spec/Documentation/Finder/RepositoryPageFinderSpec.php b/spec/Documentation/Finder/RepositoryPageFinderSpec.php new file mode 100644 index 0000000..b85b897 --- /dev/null +++ b/spec/Documentation/Finder/RepositoryPageFinderSpec.php @@ -0,0 +1,73 @@ +beConstructedWith($repository); + } + + function it_is_page_finder() + { + $this->shouldHaveType(PageFinder::class); + } + + function it_finds_documentation_page_if_documentation_was_saved_and_has_asked_page( + Repository $repository, + DocumentationId $anId, + BuiltDocumentation $built + ) { + $built->getDocumentationId()->willReturn($anId); + $built->getBuildTime()->willReturn(new \DateTimeImmutable()); + $built->getDocumentationTime()->willReturn(new \DateTimeImmutable()); + + $pageId = new PageId(basename(__FILE__)); + $publishedDocumentation = PublishedDocumentation::publish( + $built->getWrappedObject(), __DIR__ + ); + + $repository->find($anId)->willReturn($publishedDocumentation); + + $page = $this->findPage($anId, $pageId); + $page->shouldBeAnInstanceOf(Page::class); + $page->getPath()->shouldReturn(__FILE__); + } + + function it_finds_nothing_if_documentation_was_not_found( + Repository $repository, + DocumentationId $anId + ) { + $pageId = new PageId(basename(__FILE__)); + + $repository->find($anId)->willReturn(null); + + $this->findPage($anId, $pageId)->shouldReturn(null); + } + + function it_finds_nothing_if_documentation_was_found_but_page_was_not( + Repository $repository, + DocumentationId $anId, + BuiltDocumentation $built + ) { + $pageId = new PageId('no_file'); + $publishedDocumentation = PublishedDocumentation::publish( + $built->getWrappedObject(), __DIR__ + ); + + $repository->find($anId)->willReturn($publishedDocumentation); + + $this->findPage($anId, $pageId)->shouldReturn(null); + } +} diff --git a/spec/DocumentationManagerSpec.php b/spec/DocumentationManagerSpec.php index b5ecf50..26d16f1 100644 --- a/spec/DocumentationManagerSpec.php +++ b/spec/DocumentationManagerSpec.php @@ -2,15 +2,14 @@ namespace spec\Behat\Borg; -use Behat\Borg\Documentation\Builder\Builder; use Behat\Borg\Documentation\Builder\BuiltDocumentation; +use Behat\Borg\Documentation\Finder\PageFinder; use Behat\Borg\Documentation\Processor\Processor; use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Page\PageId; use Behat\Borg\Documentation\Page\Page; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; -use Behat\Borg\Documentation\Publisher\Publisher; use Behat\Borg\Documentation\Repository\Repository; use Behat\Borg\Documentation\Source; use PhpSpec\ObjectBehavior; @@ -18,9 +17,9 @@ class DocumentationManagerSpec extends ObjectBehavior { - function let(Processor $processor, Repository $repository) + function let(Processor $processor, PageFinder $pageFinder, Repository $repository) { - $this->beConstructedWith($processor, $repository); + $this->beConstructedWith($processor, $pageFinder, $repository); } function it_processes_documentation_using_processor( @@ -37,8 +36,8 @@ function it_processes_documentation_using_processor( $this->process($raw); } - function it_finds_documentation_page_if_documentation_was_saved_and_has_asked_page( - Repository $repository, + function it_finds_pages_using_finder( + PageFinder $pageFinder, DocumentationId $anId, BuiltDocumentation $built ) { @@ -48,38 +47,11 @@ function it_finds_documentation_page_if_documentation_was_saved_and_has_asked_pa $pageId = new PageId(basename(__FILE__)); $publishedDocumentation = PublishedDocumentation::publish($built->getWrappedObject(), __DIR__); + $page = new Page($publishedDocumentation, $pageId); - $repository->find($anId)->willReturn($publishedDocumentation); - - $page = $this->findPage($anId, $pageId); - $page->shouldBeAnInstanceOf(Page::class); - $page->getPath()->shouldReturn(__FILE__); - } - - function it_finds_nothing_if_documentation_was_not_found( - Repository $repository, - DocumentationId $anId - ) { - $pageId = new PageId(basename(__FILE__)); - - $repository->find($anId)->willReturn(null); - - $this->findPage($anId, $pageId)->shouldReturn(null); - } - - function it_finds_nothing_if_documentation_was_found_but_page_was_not( - Repository $repository, - DocumentationId $anId, - BuiltDocumentation $built - ) { - $pageId = new PageId('no_file'); - $publishedDocumentation = PublishedDocumentation::publish( - $built->getWrappedObject(), __DIR__ - ); - - $repository->find($anId)->willReturn($publishedDocumentation); + $pageFinder->findPage($anId, $pageId)->willReturn($page); - $this->findPage($anId, $pageId)->shouldReturn(null); + $this->findPage($anId, $pageId)->shouldReturn($page); } function it_finds_all_documentation_for_a_provided_project_name( diff --git a/src/Documentation/Finder/PageFinder.php b/src/Documentation/Finder/PageFinder.php new file mode 100644 index 0000000..47f146a --- /dev/null +++ b/src/Documentation/Finder/PageFinder.php @@ -0,0 +1,23 @@ +repository = $repository; + } + + /** + * {@inheritdoc} + */ + public function findPage(DocumentationId $documentationId, PageId $pageId) + { + if (!$documentation = $this->repository->find($documentationId)) { + return null; + } + + if (!$documentation->hasPage($pageId)) { + return null; + } + + return $documentation->getPage($pageId); + } +} diff --git a/src/DocumentationManager.php b/src/DocumentationManager.php index d1873d1..7b198b8 100644 --- a/src/DocumentationManager.php +++ b/src/DocumentationManager.php @@ -2,6 +2,7 @@ namespace Behat\Borg; +use Behat\Borg\Documentation\Finder\PageFinder; use Behat\Borg\Documentation\Processor\Processor; use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; @@ -19,6 +20,10 @@ final class DocumentationManager * @var Processor */ private $processor; + /** + * @var PageFinder + */ + private $finder; /** * @var Repository */ @@ -28,11 +33,13 @@ final class DocumentationManager * Initialize manager. * * @param Processor $processor + * @param PageFinder $finder * @param Repository $repository */ - public function __construct(Processor $processor, Repository $repository) + public function __construct(Processor $processor, PageFinder $finder, Repository $repository) { $this->processor = $processor; + $this->finder = $finder; $this->repository = $repository; } @@ -52,19 +59,11 @@ public function process(RawDocumentation $documentation) * @param DocumentationId $documentationId * @param PageId $pageId * - * @return Page|null + * @return null|Page */ public function findPage(DocumentationId $documentationId, PageId $pageId) { - if (!$documentation = $this->repository->find($documentationId)) { - return null; - } - - if (!$documentation->hasPage($pageId)) { - return null; - } - - return $documentation->getPage($pageId); + return $this->finder->findPage($documentationId, $pageId); } /** From 42833122ad3e63a864a94f75ca968c417bab30af Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 16:00:45 +0000 Subject: [PATCH 15/37] Update domain acceptance tests to pass again --- .../DocumentationContributorContext.php | 15 ++++++--- src/Documentation/Publisher/Publisher.php | 31 ----------------- tests/Fake/Documentation/FakePublisher.php | 26 +-------------- tests/Fake/Documentation/FakeRepository.php | 33 +++++++++++++++++++ 4 files changed, 45 insertions(+), 60 deletions(-) create mode 100644 tests/Fake/Documentation/FakeRepository.php diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index 90ed219..a54a413 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -2,7 +2,9 @@ use Behat\Behat\Context\Context; use Behat\Behat\Context\SnippetAcceptingContext; +use Behat\Borg\Documentation\Finder\RepositoryPageFinder; use Behat\Borg\Documentation\Page\PageId; +use Behat\Borg\Documentation\Processor\BuildingProcessor; use Behat\Borg\Documentation\ProjectDocumentationId; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; use Behat\Borg\Package\ReleasePackager; @@ -14,14 +16,15 @@ use Behat\Borg\Release\Release; use Behat\Borg\Release\Version; use Behat\Borg\ReleaseManager; +use PHPUnit_Framework_Assert as PHPUnit; use tests\Behat\Borg\Fake\Documentation\FakeBuilder; use tests\Behat\Borg\Fake\Documentation\FakeDocumentedDownload; use tests\Behat\Borg\Fake\Documentation\FakePublisher; +use tests\Behat\Borg\Fake\Documentation\FakeRepository; use tests\Behat\Borg\Fake\Documentation\FakeSource; use tests\Behat\Borg\Fake\Documentation\FakeSourceFinder; use tests\Behat\Borg\Fake\Package\FakePackageFinder; use tests\Behat\Borg\Fake\Release\FakeDownloader; -use PHPUnit_Framework_Assert as PHPUnit; /** * Describes documentation-related features from the documentation manager context. @@ -39,14 +42,18 @@ class DocumentationContributorContext implements Context, SnippetAcceptingContex */ public function __construct() { - $publisher = new FakePublisher(); + $this->downloader = new FakeDownloader(); $sourceFinder = new FakeSourceFinder(); $packageFinder = new FakePackageFinder(); - $this->downloader = new FakeDownloader(); $builder = new FakeBuilder(); + $publisher = new FakePublisher(); + $repository = new FakeRepository(); + + $processor = new BuildingProcessor($builder, $publisher, $repository); + $pageFinder = new RepositoryPageFinder($repository); $this->releaseManager = new ReleaseManager(); - $this->documentationManager = new DocumentationManager($builder, $publisher); + $this->documentationManager = new DocumentationManager($processor, $pageFinder, $repository); $releaseDownloader = new ReleaseDownloader($this->downloader); $releasePackager = new ReleasePackager($packageFinder); diff --git a/src/Documentation/Publisher/Publisher.php b/src/Documentation/Publisher/Publisher.php index 5183a84..1c2e215 100644 --- a/src/Documentation/Publisher/Publisher.php +++ b/src/Documentation/Publisher/Publisher.php @@ -3,8 +3,6 @@ namespace Behat\Borg\Documentation\Publisher; use Behat\Borg\Documentation\Builder\BuiltDocumentation; -use Behat\Borg\Documentation\DocumentationId; -use Behat\Borg\Documentation\Exception\RequestedDocumentationWasNotPublished; /** * Publishes built documentation. @@ -19,33 +17,4 @@ interface Publisher * @return PublishedDocumentation */ public function publish(BuiltDocumentation $builtDocumentation); - - /** - * Checks if documentation with the id was published. - * - * @param DocumentationId $anId - * - * @return Boolean - */ - public function hasPublished(DocumentationId $anId); - - /** - * Gets published documentation by its unique ID. - * - * @param DocumentationId $anId - * - * @return PublishedDocumentation - * - * @throws RequestedDocumentationWasNotPublished - */ - public function getPublished(DocumentationId $anId); - - /** - * Gets all available documentation for provided project name. - * - * @param string $projectName - * - * @return PublishedDocumentation[] - */ - public function findForProject($projectName); } diff --git a/tests/Fake/Documentation/FakePublisher.php b/tests/Fake/Documentation/FakePublisher.php index 04fc579..1eeccdb 100644 --- a/tests/Fake/Documentation/FakePublisher.php +++ b/tests/Fake/Documentation/FakePublisher.php @@ -3,37 +3,13 @@ namespace tests\Behat\Borg\Fake\Documentation; use Behat\Borg\Documentation\Builder\BuiltDocumentation; -use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; use Behat\Borg\Documentation\Publisher\Publisher; final class FakePublisher implements Publisher { - private $documentation; - public function publish(BuiltDocumentation $builtDocumentation) { - $publishedDocumentation = PublishedDocumentation::publish($builtDocumentation, __DIR__ . '/build'); - $this->documentation[(string)$builtDocumentation->getDocumentationId()] = $publishedDocumentation; - } - - public function hasPublished(DocumentationId $anId) - { - return isset($this->documentation['' . $anId]); - } - - public function getPublished(DocumentationId $anId) - { - return $this->documentation[(string)$anId]; - } - - public function findForProject($projectName) - { - return array_filter( - $this->documentation, - function (PublishedDocumentation $documentation) use ($projectName) { - return strtolower($projectName) == $documentation->getDocumentationId()->getProjectName(); - } - ); + return PublishedDocumentation::publish($builtDocumentation, __DIR__ . '/build'); } } diff --git a/tests/Fake/Documentation/FakeRepository.php b/tests/Fake/Documentation/FakeRepository.php new file mode 100644 index 0000000..3cce74e --- /dev/null +++ b/tests/Fake/Documentation/FakeRepository.php @@ -0,0 +1,33 @@ +documentation[(string)$published->getDocumentationId()] = $published; + } + + public function find(DocumentationId $anId) + { + return $this->documentation[(string)$anId]; + } + + public function findForProject($projectName) + { + return array_filter( + $this->documentation, + function (PublishedDocumentation $documentation) use ($projectName) { + return strtolower($projectName) == $documentation->getDocumentationId( + )->getProjectName(); + } + ); + } +} From de1997d3378f831c94d7e9bb1ea4d686ee2a7e68 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 16:02:59 +0000 Subject: [PATCH 16/37] Simplify domain context initialization --- .../bootstrap/DocumentationContributorContext.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index a54a413..821a7a2 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -43,21 +43,16 @@ class DocumentationContributorContext implements Context, SnippetAcceptingContex public function __construct() { $this->downloader = new FakeDownloader(); - $sourceFinder = new FakeSourceFinder(); - $packageFinder = new FakePackageFinder(); - $builder = new FakeBuilder(); - $publisher = new FakePublisher(); $repository = new FakeRepository(); - - $processor = new BuildingProcessor($builder, $publisher, $repository); + $processor = new BuildingProcessor(new FakeBuilder(), new FakePublisher(), $repository); $pageFinder = new RepositoryPageFinder($repository); - $this->releaseManager = new ReleaseManager(); $this->documentationManager = new DocumentationManager($processor, $pageFinder, $repository); + $this->releaseManager = new ReleaseManager(); $releaseDownloader = new ReleaseDownloader($this->downloader); - $releasePackager = new ReleasePackager($packageFinder); - $documentingBuilder = new PackagedDocumentationBuilder($sourceFinder, $this->documentationManager); + $releasePackager = new ReleasePackager(new FakePackageFinder()); + $documentingBuilder = new PackagedDocumentationBuilder(new FakeSourceFinder(), $this->documentationManager); $this->releaseManager->registerListener($releaseDownloader); $releaseDownloader->registerListener($releasePackager); From 6273f3f72623f15faa538a9d4c6af1ef446a7796 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 16:15:47 +0000 Subject: [PATCH 17/37] Fix integration tests --- .../Publisher/DirectoryPublisher.php | 49 ----------- .../Documentation/DirectoryPublisherTest.php | 85 ------------------- 2 files changed, 134 deletions(-) diff --git a/src/Documentation/Publisher/DirectoryPublisher.php b/src/Documentation/Publisher/DirectoryPublisher.php index 9786456..7ab25f5 100644 --- a/src/Documentation/Publisher/DirectoryPublisher.php +++ b/src/Documentation/Publisher/DirectoryPublisher.php @@ -3,10 +3,7 @@ namespace Behat\Borg\Documentation\Publisher; use Behat\Borg\Documentation\Builder\BuiltDocumentation; -use Behat\Borg\Documentation\DocumentationId; -use Behat\Borg\Documentation\Exception\RequestedDocumentationWasNotPublished; use Symfony\Component\Filesystem\Filesystem; -use Symfony\Component\Finder\Finder; /** * Documentation publisher that simply moves built docs into a public directory. @@ -35,60 +32,14 @@ public function publish(BuiltDocumentation $builtDocumentation) $publishedDocumentation = PublishedDocumentation::publish($builtDocumentation, $publishPath); $this->moveDocumentation($buildPath, $publishPath); - $this->writePublishingMeta($publishPath, $publishedDocumentation); return $publishedDocumentation; } - /** - * {@inheritdoc} - */ - public function hasPublished(DocumentationId $anId) - { - return file_exists("{$this->publishPath}/{$anId}/publish.meta"); - } - - /** - * {@inheritdoc} - */ - public function getPublished(DocumentationId $anId) - { - if (!$this->hasPublished($anId)) { - throw new RequestedDocumentationWasNotPublished("Documentation `{$anId}` was not published."); - } - - return $this->readPublishingMeta($this->publishPath . '/' . $anId); - } - - /** - * {@inheritdoc} - */ - public function findForProject($projectName) - { - $documentation = []; - $projectPath = $this->publishPath . '/' . $projectName; - - foreach (Finder::create()->depth(0)->directories()->in($projectPath) as $dir) { - $documentation[] = unserialize(file_get_contents($dir . '/publish.meta')); - } - - return $documentation; - } - private function moveDocumentation($buildPath, $publishPath) { $filesystem = new Filesystem(); $filesystem->mirror($buildPath, $publishPath); $filesystem->remove($buildPath); } - - private function writePublishingMeta($publishPath, PublishedDocumentation $documentation) - { - file_put_contents($publishPath . '/publish.meta', serialize($documentation)); - } - - private function readPublishingMeta($publishPath) - { - return unserialize(file_get_contents($publishPath . '/publish.meta')); - } } diff --git a/tests/Documentation/DirectoryPublisherTest.php b/tests/Documentation/DirectoryPublisherTest.php index d09467c..df39207 100644 --- a/tests/Documentation/DirectoryPublisherTest.php +++ b/tests/Documentation/DirectoryPublisherTest.php @@ -45,90 +45,5 @@ function it_publishes_documentation_by_moving_it_to_appropriate_folder() PublishedDocumentation::publish($builtDoc, $this->tempPublishPath . '/built_doc'), $publishedDoc ); - $this->assertFileExists($this->tempPublishPath . '/built_doc/my_file'); - $this->assertEquals($publishedDoc, unserialize(file_get_contents( - $this->tempPublishPath . '/built_doc/publish.meta' - ))); - } - - /** @test */ - function it_can_check_if_documentation_was_published() - { - $anId = $this->getMock(DocumentationId::class); - $anId->method('__toString')->willReturn('my_doc'); - $builtDoc = $this->getMock(BuiltDocumentation::class); - $publishedDoc = PublishedDocumentation::publish($builtDoc, $this->tempPublishPath . '/my_doc'); - - (new Filesystem())->mkdir($this->tempPublishPath . '/my_doc'); - file_put_contents($this->tempPublishPath . '/my_doc/publish.meta', serialize($publishedDoc)); - - $this->assertTrue($this->publisher->hasPublished($anId)); - $this->assertFalse($this->publisher->hasPublished($this->getMock(DocumentationId::class))); - } - - /** @test */ - function it_can_get_published_documentation() - { - $anId = $this->getMock(DocumentationId::class); - $anId->method('__toString')->willReturn('my_doc'); - $builtDoc = $this->getMock(BuiltDocumentation::class); - $publishedDoc = PublishedDocumentation::publish($builtDoc, $this->tempPublishPath . '/my_doc'); - - (new Filesystem())->mkdir($this->tempPublishPath . '/my_doc'); - file_put_contents( - $this->tempPublishPath . '/my_doc/publish.meta', serialize($publishedDoc) - ); - - $this->assertEquals($publishedDoc, $this->publisher->getPublished($anId)); - } - - /** @test */ - function it_can_find_all_available_documentation_for_provided_project_name() - { - $v1Id = $this->getMock(DocumentationId::class); - $v1Id->method('__toString')->willReturn('my_doc/v1.0'); - $v1BuiltDoc = $this->getMock(BuiltDocumentation::class); - $v1Doc = PublishedDocumentation::publish($v1BuiltDoc, $this->tempPublishPath . '/my_doc/v1.0'); - - $v2Id = $this->getMock(DocumentationId::class); - $v2Id->method('__toString')->willReturn('my_doc/v2.0'); - $v2BuiltDoc = $this->getMock(BuiltDocumentation::class); - $v2Doc = PublishedDocumentation::publish($v2BuiltDoc, $this->tempPublishPath . '/my_doc/v2.0'); - - (new Filesystem()) - ->dumpFile($this->tempPublishPath . '/my_doc/v1.0/publish.meta', serialize($v1Doc)); - (new Filesystem()) - ->dumpFile($this->tempPublishPath . '/my_doc/v2.0/publish.meta', serialize($v2Doc)); - - $documentation = $this->publisher->findForProject('my_doc'); - - $this->assertContains($v1Doc, $documentation, 'v1 documentation is not found', false, false); - $this->assertContains($v2Doc, $documentation, 'v2 documentation is not found', false, false); - } - - /** @test */ - function it_ignores_sub_folders_of_documentation_versions() - { - $anId = $this->getMock(DocumentationId::class); - $anId->method('__toString')->willReturn('my_doc/v1.0'); - $builtDoc = $this->getMock(BuiltDocumentation::class); - $doc = PublishedDocumentation::publish($builtDoc, $this->tempPublishPath . '/my_doc/v1.0'); - - (new Filesystem()) - ->dumpFile( - $this->tempPublishPath . '/my_doc/v1.0/publish.meta', serialize($doc)); - (new Filesystem()) - ->dumpFile($this->tempPublishPath . '/my_doc/v1.0/subfolder/publish.meta', serialize($doc)); - - $this->assertCount(1, $this->publisher->findForProject('my_doc')); - } - - /** - * @test - * @expectedException \Behat\Borg\Documentation\Exception\RequestedDocumentationWasNotPublished - */ - function it_throws_an_exception_when_trying_to_get_unpublished_documentation() - { - $this->publisher->getPublished($this->getMock(DocumentationId::class)); } } From aa01ece8d25a2f9140c1feb5d65de6971eadc3c6 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 20:07:21 +0000 Subject: [PATCH 18/37] Make smoke tests green again by introducing FilesystemRepository --- composer.json | 3 +- composer.lock | 131 +++++++++++++----- .../Resources/config/services.xml | 21 +++ .../Documentation/FilesystemRepository.php | 42 ++++++ 4 files changed, 158 insertions(+), 39 deletions(-) create mode 100644 src/Application/Infrastructure/Documentation/FilesystemRepository.php diff --git a/composer.json b/composer.json index 7e98aef..2d74499 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,8 @@ "sensio/distribution-bundle": "~3.0", "sensio/framework-extra-bundle": "~3.0", "incenteev/composer-parameter-handler": "~2.0", - "knplabs/github-api": "~1.4.1" + "knplabs/github-api": "~1.4.1", + "everzet/persisted-objects": "~1.0.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index a669959..31f98a4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "1e972d16a254efb1df7e562b4cd7931b", + "hash": "3c42e9ef2e156f12bf5cbad58a42bcdc", "packages": [ { "name": "doctrine/annotations", @@ -358,22 +358,27 @@ }, { "name": "doctrine/lexer", - "version": "v1.0", + "version": "v1.0.1", "source": { "type": "git", "url": "https://github.com/doctrine/lexer.git", - "reference": "2f708a85bb3aab5d99dab8be435abd73e0b18acb" + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/lexer/zipball/2f708a85bb3aab5d99dab8be435abd73e0b18acb", - "reference": "2f708a85bb3aab5d99dab8be435abd73e0b18acb", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/83893c552fd2045dd78aef794c31e694c37c0b8c", + "reference": "83893c552fd2045dd78aef794c31e694c37c0b8c", "shasum": "" }, "require": { "php": ">=5.3.2" }, "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, "autoload": { "psr-0": { "Doctrine\\Common\\Lexer\\": "lib/" @@ -384,20 +389,17 @@ "MIT" ], "authors": [ - { - "name": "Guilherme Blanco", - "email": "guilhermeblanco@gmail.com", - "homepage": "http://www.instaclick.com" - }, { "name": "Roman Borschel", "email": "roman@code-factory.org" }, + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, { "name": "Johannes Schmitt", - "email": "schmittjoh@gmail.com", - "homepage": "https://github.com/schmittjoh", - "role": "Developer of wrapped JMSSerializerBundle" + "email": "schmittjoh@gmail.com" } ], "description": "Base library for a lexer that can be used in Top-Down, Recursive Descent Parsers.", @@ -406,7 +408,60 @@ "lexer", "parser" ], - "time": "2013-01-12 18:59:04" + "time": "2014-09-09 13:34:57" + }, + { + "name": "everzet/persisted-objects", + "version": "v1.0.0", + "source": { + "type": "git", + "url": "https://github.com/everzet/persisted-objects.git", + "reference": "4d312d7acb60fa13f3e20d5f42f286765aced275" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/everzet/persisted-objects/zipball/4d312d7acb60fa13f3e20d5f42f286765aced275", + "reference": "4d312d7acb60fa13f3e20d5f42f286765aced275", + "shasum": "" + }, + "require": { + "php": "~5.4" + }, + "require-dev": { + "phpunit/phpunit": "~4.4.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Everzet\\PersistedObjects\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Konstantin Kudryashov", + "email": "ever.zet@gmail.com", + "homepage": "http://everzet.com" + } + ], + "description": "Overly simplistic persistance implementations for functional testing", + "homepage": "https://github.com/everzet/persisted-objects", + "keywords": [ + "BDD", + "ddd", + "persistance", + "repository", + "test" + ], + "time": "2014-12-19 17:36:03" }, { "name": "guzzle/guzzle", @@ -865,17 +920,17 @@ }, { "name": "sensio/distribution-bundle", - "version": "v3.0.14", + "version": "v3.0.15", "target-dir": "Sensio/Bundle/DistributionBundle", "source": { "type": "git", "url": "https://github.com/sensiolabs/SensioDistributionBundle.git", - "reference": "dc20d5ab3251587b047859ca2fc06c1b88a38d00" + "reference": "0692cd6a8fcf645abce8ea45f7cbbd1942e2b23c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sensiolabs/SensioDistributionBundle/zipball/dc20d5ab3251587b047859ca2fc06c1b88a38d00", - "reference": "dc20d5ab3251587b047859ca2fc06c1b88a38d00", + "url": "https://api.github.com/repos/sensiolabs/SensioDistributionBundle/zipball/0692cd6a8fcf645abce8ea45f7cbbd1942e2b23c", + "reference": "0692cd6a8fcf645abce8ea45f7cbbd1942e2b23c", "shasum": "" }, "require": { @@ -914,7 +969,7 @@ "configuration", "distribution" ], - "time": "2014-12-30 08:41:47" + "time": "2015-01-07 07:13:43" }, { "name": "sensio/framework-extra-bundle", @@ -1134,16 +1189,16 @@ }, { "name": "symfony/monolog-bundle", - "version": "v2.7.0", + "version": "v2.7.1", "source": { "type": "git", "url": "https://github.com/symfony/MonologBundle.git", - "reference": "e8f71c91a3784f3fa1a75fb1f7f4d4826c5f2773" + "reference": "9320b6863404c70ebe111e9040dab96f251de7ac" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/MonologBundle/zipball/e8f71c91a3784f3fa1a75fb1f7f4d4826c5f2773", - "reference": "e8f71c91a3784f3fa1a75fb1f7f4d4826c5f2773", + "url": "https://api.github.com/repos/symfony/MonologBundle/zipball/9320b6863404c70ebe111e9040dab96f251de7ac", + "reference": "9320b6863404c70ebe111e9040dab96f251de7ac", "shasum": "" }, "require": { @@ -1189,7 +1244,7 @@ "log", "logging" ], - "time": "2014-12-28 16:37:56" + "time": "2015-01-04 20:21:17" }, { "name": "symfony/swiftmailer-bundle", @@ -1250,23 +1305,23 @@ }, { "name": "symfony/symfony", - "version": "v2.6.1", + "version": "v2.6.3", "source": { "type": "git", "url": "https://github.com/symfony/symfony.git", - "reference": "d805dfd67950848ec0338b4acd75777b340977b7" + "reference": "c34ef418015793a4653f2670afb69dd167ebf578" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/symfony/zipball/d805dfd67950848ec0338b4acd75777b340977b7", - "reference": "d805dfd67950848ec0338b4acd75777b340977b7", + "url": "https://api.github.com/repos/symfony/symfony/zipball/c34ef418015793a4653f2670afb69dd167ebf578", + "reference": "c34ef418015793a4653f2670afb69dd167ebf578", "shasum": "" }, "require": { - "doctrine/common": "~2.2", + "doctrine/common": "~2.3", "php": ">=5.3.3", "psr/log": "~1.0", - "twig/twig": "~1.12" + "twig/twig": "~1.12,>=1.12.3" }, "replace": { "symfony/browser-kit": "self.version", @@ -1322,7 +1377,7 @@ "egulias/email-validator": "~1.2", "ircmaxell/password-compat": "~1.0", "monolog/monolog": "~1.11", - "ocramius/proxy-manager": ">=0.3.1,<0.6-dev", + "ocramius/proxy-manager": "~0.4|~1.0", "propel/propel1": "~1.6" }, "type": "library", @@ -1362,7 +1417,7 @@ "keywords": [ "framework" ], - "time": "2014-12-03 16:40:43" + "time": "2015-01-07 14:47:29" }, { "name": "twig/extensions", @@ -2022,16 +2077,16 @@ }, { "name": "phpspec/phpspec", - "version": "2.1.0", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/phpspec/phpspec.git", - "reference": "3d2ac6c2da3d7c1c42b966a39b0754bd055b4c60" + "reference": "66a1df93099282b1514e9e001fcf6e9393f7783d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/phpspec/zipball/3d2ac6c2da3d7c1c42b966a39b0754bd055b4c60", - "reference": "3d2ac6c2da3d7c1c42b966a39b0754bd055b4c60", + "url": "https://api.github.com/repos/phpspec/phpspec/zipball/66a1df93099282b1514e9e001fcf6e9393f7783d", + "reference": "66a1df93099282b1514e9e001fcf6e9393f7783d", "shasum": "" }, "require": { @@ -2047,7 +2102,7 @@ "symfony/yaml": "~2.1" }, "require-dev": { - "behat/behat": "~3.0", + "behat/behat": "~3.0,>=3.0.11", "bossa/phpspec2-expect": "~1.0", "symfony/filesystem": "~2.1" }, @@ -2094,7 +2149,7 @@ "testing", "tests" ], - "time": "2014-12-14 09:37:32" + "time": "2015-01-09 13:21:45" }, { "name": "phpspec/prophecy", diff --git a/src/Application/DocumentationBundle/Resources/config/services.xml b/src/Application/DocumentationBundle/Resources/config/services.xml index 6254d90..e537386 100644 --- a/src/Application/DocumentationBundle/Resources/config/services.xml +++ b/src/Application/DocumentationBundle/Resources/config/services.xml @@ -48,8 +48,29 @@ + + + + + + + %documentation.publisher.path%/published.meta + + + + + + + + repo = new FileRepository($path, $this); + } + + public function save(PublishedDocumentation $documentation) + { + $this->repo->save($documentation); + } + + public function find(DocumentationId $documentationId) + { + return $this->repo->findById((string)$documentationId); + } + + public function findForProject($projectName) + { + return array_filter( + $this->repo->getAll(), + function (PublishedDocumentation $documentation) use ($projectName) { + return strtolower($projectName) == $documentation->getDocumentationId()->getProjectName(); + } + ); + } + + public function getIdentity($object) + { + return (string)$object->getDocumentationId(); + } +} From b7aacd0031e4a89cce76f6aa8086dae40776fd7b Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 20:34:46 +0000 Subject: [PATCH 19/37] Rename DocumentationManager::getAllDocumentation() to findProjectDocumentation() --- features/bootstrap/DocumentationContributorContext.php | 2 +- .../Controller/DocumentationController.php | 2 +- src/DocumentationManager.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index 821a7a2..35e1304 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -163,7 +163,7 @@ public function documentationVersionShouldBeInTheList($project, $versionString) function (PublishedDocumentation $documentation) { return (string)$documentation->getDocumentationId(); }, - $this->documentationManager->getAvailableDocumentation($project) + $this->documentationManager->findProjectDocumentation($project) ), 'Documentation for provided version not found in the list.' ); diff --git a/src/Application/DocumentationBundle/Controller/DocumentationController.php b/src/Application/DocumentationBundle/Controller/DocumentationController.php index 05f1efd..6218af1 100644 --- a/src/Application/DocumentationBundle/Controller/DocumentationController.php +++ b/src/Application/DocumentationBundle/Controller/DocumentationController.php @@ -93,7 +93,7 @@ public function documentationPageAction($project, $version, $path) return $this->render("documentation:{$page}", [ 'page' => $page, - 'allPublished' => $manager->getAvailableDocumentation($project) + 'allPublished' => $manager->findProjectDocumentation($project) ]); } diff --git a/src/DocumentationManager.php b/src/DocumentationManager.php index 7b198b8..e4b8971 100644 --- a/src/DocumentationManager.php +++ b/src/DocumentationManager.php @@ -67,13 +67,13 @@ public function findPage(DocumentationId $documentationId, PageId $pageId) } /** - * Tries to find all available documentation for provided project name. + * Find all available documentation for a provided project. * * @param string $projectName * * @return PublishedDocumentation[] */ - public function getAvailableDocumentation($projectName) + public function findProjectDocumentation($projectName) { return $this->repository->findForProject($projectName); } From f983e9ed56ea5dbfc2218c57d055114b32ce44c8 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 20:36:58 +0000 Subject: [PATCH 20/37] Rename DocumentationManager to Documenter --- features/bootstrap/DocumentationContributorContext.php | 4 ++-- .../Controller/DocumentationController.php | 10 +++++----- .../DocumentationBundle/Resources/config/services.xml | 6 +++--- src/{DocumentationManager.php => Documenter.php} | 2 +- .../PackagedDocumentationBuilder.php | 8 ++++---- 5 files changed, 15 insertions(+), 15 deletions(-) rename src/{DocumentationManager.php => Documenter.php} (98%) diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index 35e1304..9f1780d 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -10,7 +10,7 @@ use Behat\Borg\Package\ReleasePackager; use Behat\Borg\Package\Package; use Behat\Borg\PackageDocumentation\PackagedDocumentationBuilder; -use Behat\Borg\DocumentationManager; +use Behat\Borg\Documenter; use Behat\Borg\Release\ReleaseDownloader; use Behat\Borg\Release\Repository; use Behat\Borg\Release\Release; @@ -47,7 +47,7 @@ public function __construct() $processor = new BuildingProcessor(new FakeBuilder(), new FakePublisher(), $repository); $pageFinder = new RepositoryPageFinder($repository); - $this->documentationManager = new DocumentationManager($processor, $pageFinder, $repository); + $this->documentationManager = new Documenter($processor, $pageFinder, $repository); $this->releaseManager = new ReleaseManager(); $releaseDownloader = new ReleaseDownloader($this->downloader); diff --git a/src/Application/DocumentationBundle/Controller/DocumentationController.php b/src/Application/DocumentationBundle/Controller/DocumentationController.php index 6218af1..a9fe278 100644 --- a/src/Application/DocumentationBundle/Controller/DocumentationController.php +++ b/src/Application/DocumentationBundle/Controller/DocumentationController.php @@ -4,7 +4,7 @@ use Behat\Borg\Documentation\Page\PageId; use Behat\Borg\Documentation\ProjectDocumentationId; -use Behat\Borg\DocumentationManager; +use Behat\Borg\Documenter; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -83,7 +83,7 @@ public function documentationIndexAction($project, $version, $path = 'index.html */ public function documentationPageAction($project, $version, $path) { - $manager = $this->getDocumentationManager(); + $manager = $this->getDocumenter(); $documentationId = new ProjectDocumentationId($project, $version); $pageId = new PageId($path); @@ -98,10 +98,10 @@ public function documentationPageAction($project, $version, $path) } /** - * @return DocumentationManager + * @return Documenter */ - private function getDocumentationManager() + private function getDocumenter() { - return $this->get('documentation.manager'); + return $this->get('documentation.documenter'); } } diff --git a/src/Application/DocumentationBundle/Resources/config/services.xml b/src/Application/DocumentationBundle/Resources/config/services.xml index e537386..80c1d0f 100644 --- a/src/Application/DocumentationBundle/Resources/config/services.xml +++ b/src/Application/DocumentationBundle/Resources/config/services.xml @@ -37,7 +37,7 @@ class="Behat\Borg\PackageDocumentation\PackagedDocumentationBuilder" public="false"> - + - + diff --git a/src/DocumentationManager.php b/src/Documenter.php similarity index 98% rename from src/DocumentationManager.php rename to src/Documenter.php index e4b8971..af7bf59 100644 --- a/src/DocumentationManager.php +++ b/src/Documenter.php @@ -14,7 +14,7 @@ /** * Manages documentation by providing high-level accessor methods. */ -final class DocumentationManager +final class Documenter { /** * @var Processor diff --git a/src/PackageDocumentation/PackagedDocumentationBuilder.php b/src/PackageDocumentation/PackagedDocumentationBuilder.php index 4db4dd6..8f8d4cb 100644 --- a/src/PackageDocumentation/PackagedDocumentationBuilder.php +++ b/src/PackageDocumentation/PackagedDocumentationBuilder.php @@ -4,7 +4,7 @@ use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\Finder\SourceFinder; -use Behat\Borg\DocumentationManager; +use Behat\Borg\Documenter; use Behat\Borg\Package\Listener\PackageListener; use Behat\Borg\Package\PackageDownload; @@ -18,7 +18,7 @@ final class PackagedDocumentationBuilder implements PackageListener */ private $finder; /** - * @var DocumentationManager + * @var Documenter */ private $manager; @@ -26,9 +26,9 @@ final class PackagedDocumentationBuilder implements PackageListener * Initializes listener. * * @param SourceFinder $finder - * @param DocumentationManager $manager + * @param Documenter $manager */ - public function __construct(SourceFinder $finder, DocumentationManager $manager) + public function __construct(SourceFinder $finder, Documenter $manager) { $this->finder = $finder; $this->manager = $manager; From 4e943ed4c7d53947b2321be508bc57723f30421d Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 20:42:35 +0000 Subject: [PATCH 21/37] Switch FakeRepository to use InMemoryRepository --- tests/Fake/Documentation/FakeRepository.php | 25 +++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/tests/Fake/Documentation/FakeRepository.php b/tests/Fake/Documentation/FakeRepository.php index 3cce74e..dfa514d 100644 --- a/tests/Fake/Documentation/FakeRepository.php +++ b/tests/Fake/Documentation/FakeRepository.php @@ -5,29 +5,40 @@ use Behat\Borg\Documentation\DocumentationId; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; use Behat\Borg\Documentation\Repository\Repository; +use Everzet\PersistedObjects\InMemoryRepository; +use Everzet\PersistedObjects\ObjectIdentifier; -final class FakeRepository implements Repository +final class FakeRepository implements Repository, ObjectIdentifier { - private $documentation; + private $repository; + + public function __construct() + { + $this->repository = new InMemoryRepository($this); + } public function save(PublishedDocumentation $published) { - $this->documentation[(string)$published->getDocumentationId()] = $published; + $this->repository->save($published); } public function find(DocumentationId $anId) { - return $this->documentation[(string)$anId]; + return $this->repository->findById((string)$anId); } public function findForProject($projectName) { return array_filter( - $this->documentation, + $this->repository->getAll(), function (PublishedDocumentation $documentation) use ($projectName) { - return strtolower($projectName) == $documentation->getDocumentationId( - )->getProjectName(); + return strtolower($projectName) == $documentation->getDocumentationId()->getProjectName(); } ); } + + public function getIdentity($object) + { + return (string)$object->getDocumentationId(); + } } From 90d8930180b660116db26e36d830d3fdbbeb7bfb Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 20:54:46 +0000 Subject: [PATCH 22/37] Merge PageFinder logic back into Documenter Logic footprint is too small to deserve separate object. In fact, separate object decreases cohesion. And we don't want that. --- .../DocumentationContributorContext.php | 4 +- spec/DocumentationManagerSpec.php | 74 ------------------- ...yPageFinderSpec.php => DocumenterSpec.php} | 47 +++++++++--- .../Resources/config/services.xml | 7 -- src/Documentation/Finder/PageFinder.php | 23 ------ .../Finder/RepositoryPageFinder.php | 44 ----------- src/Documenter.php | 19 ++--- 7 files changed, 49 insertions(+), 169 deletions(-) delete mode 100644 spec/DocumentationManagerSpec.php rename spec/{Documentation/Finder/RepositoryPageFinderSpec.php => DocumenterSpec.php} (58%) delete mode 100644 src/Documentation/Finder/PageFinder.php delete mode 100644 src/Documentation/Finder/RepositoryPageFinder.php diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index 9f1780d..6e518f8 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -2,7 +2,6 @@ use Behat\Behat\Context\Context; use Behat\Behat\Context\SnippetAcceptingContext; -use Behat\Borg\Documentation\Finder\RepositoryPageFinder; use Behat\Borg\Documentation\Page\PageId; use Behat\Borg\Documentation\Processor\BuildingProcessor; use Behat\Borg\Documentation\ProjectDocumentationId; @@ -45,9 +44,8 @@ public function __construct() $this->downloader = new FakeDownloader(); $repository = new FakeRepository(); $processor = new BuildingProcessor(new FakeBuilder(), new FakePublisher(), $repository); - $pageFinder = new RepositoryPageFinder($repository); - $this->documentationManager = new Documenter($processor, $pageFinder, $repository); + $this->documentationManager = new Documenter($processor, $repository); $this->releaseManager = new ReleaseManager(); $releaseDownloader = new ReleaseDownloader($this->downloader); diff --git a/spec/DocumentationManagerSpec.php b/spec/DocumentationManagerSpec.php deleted file mode 100644 index 26d16f1..0000000 --- a/spec/DocumentationManagerSpec.php +++ /dev/null @@ -1,74 +0,0 @@ -beConstructedWith($processor, $pageFinder, $repository); - } - - function it_processes_documentation_using_processor( - DocumentationId $anId, - Source $source, - Processor $processor - ) { - $raw = new RawDocumentation( - $anId->getWrappedObject(), new \DateTimeImmutable(), $source->getWrappedObject() - ); - - $processor->process($raw)->shouldBeCalled(); - - $this->process($raw); - } - - function it_finds_pages_using_finder( - PageFinder $pageFinder, - DocumentationId $anId, - BuiltDocumentation $built - ) { - $built->getDocumentationId()->willReturn($anId); - $built->getBuildTime()->willReturn(new \DateTimeImmutable()); - $built->getDocumentationTime()->willReturn(new \DateTimeImmutable()); - - $pageId = new PageId(basename(__FILE__)); - $publishedDocumentation = PublishedDocumentation::publish($built->getWrappedObject(), __DIR__); - $page = new Page($publishedDocumentation, $pageId); - - $pageFinder->findPage($anId, $pageId)->willReturn($page); - - $this->findPage($anId, $pageId)->shouldReturn($page); - } - - function it_finds_all_documentation_for_a_provided_project_name( - Repository $repository, - DocumentationId $anId, - BuiltDocumentation $built - ) { - $built->getDocumentationId()->willReturn($anId); - $built->getBuildTime()->willReturn(new \DateTimeImmutable()); - $built->getDocumentationTime()->willReturn(new \DateTimeImmutable()); - - $publishedDocumentation = PublishedDocumentation::publish( - $built->getWrappedObject(), __DIR__ - ); - - $repository->findForProject('my/project')->willReturn([$publishedDocumentation]); - - $this->getAvailableDocumentation('my/project')->shouldReturn([$publishedDocumentation]); - } -} diff --git a/spec/Documentation/Finder/RepositoryPageFinderSpec.php b/spec/DocumenterSpec.php similarity index 58% rename from spec/Documentation/Finder/RepositoryPageFinderSpec.php rename to spec/DocumenterSpec.php index b85b897..bda3959 100644 --- a/spec/Documentation/Finder/RepositoryPageFinderSpec.php +++ b/spec/DocumenterSpec.php @@ -1,27 +1,38 @@ beConstructedWith($repository); + $this->beConstructedWith($processor, $repository); } - function it_is_page_finder() - { - $this->shouldHaveType(PageFinder::class); + function it_processes_documentation_using_processor( + DocumentationId $anId, + Source $source, + Processor $processor + ) { + $raw = new RawDocumentation( + $anId->getWrappedObject(), new \DateTimeImmutable(), $source->getWrappedObject() + ); + + $processor->process($raw)->shouldBeCalled(); + + $this->process($raw); } function it_finds_documentation_page_if_documentation_was_saved_and_has_asked_page( @@ -70,4 +81,22 @@ function it_finds_nothing_if_documentation_was_found_but_page_was_not( $this->findPage($anId, $pageId)->shouldReturn(null); } + + function it_finds_all_documentation_for_a_provided_project_name( + Repository $repository, + DocumentationId $anId, + BuiltDocumentation $built + ) { + $built->getDocumentationId()->willReturn($anId); + $built->getBuildTime()->willReturn(new \DateTimeImmutable()); + $built->getDocumentationTime()->willReturn(new \DateTimeImmutable()); + + $publishedDocumentation = PublishedDocumentation::publish( + $built->getWrappedObject(), __DIR__ + ); + + $repository->findForProject('my/project')->willReturn([$publishedDocumentation]); + + $this->findProjectDocumentation('my/project')->shouldReturn([$publishedDocumentation]); + } } diff --git a/src/Application/DocumentationBundle/Resources/config/services.xml b/src/Application/DocumentationBundle/Resources/config/services.xml index 80c1d0f..c9c8f99 100644 --- a/src/Application/DocumentationBundle/Resources/config/services.xml +++ b/src/Application/DocumentationBundle/Resources/config/services.xml @@ -49,7 +49,6 @@ - @@ -59,12 +58,6 @@ %documentation.publisher.path%/published.meta - - - - diff --git a/src/Documentation/Finder/PageFinder.php b/src/Documentation/Finder/PageFinder.php deleted file mode 100644 index 47f146a..0000000 --- a/src/Documentation/Finder/PageFinder.php +++ /dev/null @@ -1,23 +0,0 @@ -repository = $repository; - } - - /** - * {@inheritdoc} - */ - public function findPage(DocumentationId $documentationId, PageId $pageId) - { - if (!$documentation = $this->repository->find($documentationId)) { - return null; - } - - if (!$documentation->hasPage($pageId)) { - return null; - } - - return $documentation->getPage($pageId); - } -} diff --git a/src/Documenter.php b/src/Documenter.php index af7bf59..fcd33bf 100644 --- a/src/Documenter.php +++ b/src/Documenter.php @@ -2,7 +2,6 @@ namespace Behat\Borg; -use Behat\Borg\Documentation\Finder\PageFinder; use Behat\Borg\Documentation\Processor\Processor; use Behat\Borg\Documentation\RawDocumentation; use Behat\Borg\Documentation\DocumentationId; @@ -20,10 +19,6 @@ final class Documenter * @var Processor */ private $processor; - /** - * @var PageFinder - */ - private $finder; /** * @var Repository */ @@ -33,13 +28,11 @@ final class Documenter * Initialize manager. * * @param Processor $processor - * @param PageFinder $finder * @param Repository $repository */ - public function __construct(Processor $processor, PageFinder $finder, Repository $repository) + public function __construct(Processor $processor, Repository $repository) { $this->processor = $processor; - $this->finder = $finder; $this->repository = $repository; } @@ -63,7 +56,15 @@ public function process(RawDocumentation $documentation) */ public function findPage(DocumentationId $documentationId, PageId $pageId) { - return $this->finder->findPage($documentationId, $pageId); + if (!$documentation = $this->repository->find($documentationId)) { + return null; + } + + if (!$documentation->hasPage($pageId)) { + return null; + } + + return $documentation->getPage($pageId); } /** From 7cd13bdbcc93f4b56632eaa184605e3ee5800201 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 21:21:13 +0000 Subject: [PATCH 23/37] Make current documentation scenarios green By introducing CurrentDocumentationRepository, who's sole responsibility is to handle `current` documentation. --- .../DocumentationContributorContext.php | 3 +- ...current_documentation_is_available.feature | 2 +- .../CurrentDocumentationRepositorySpec.php | 89 +++++++++++++++++++ .../Repository/CurrentableRepositorySpec.php | 14 +++ .../CurrentDocumentationRepository.php | 66 ++++++++++++++ .../Repository/CurrentableRepository.php | 7 ++ 6 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php create mode 100644 spec/Documentation/Repository/CurrentableRepositorySpec.php create mode 100644 src/Documentation/Repository/CurrentDocumentationRepository.php create mode 100644 src/Documentation/Repository/CurrentableRepository.php diff --git a/features/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index 6e518f8..784bbb8 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -6,6 +6,7 @@ use Behat\Borg\Documentation\Processor\BuildingProcessor; use Behat\Borg\Documentation\ProjectDocumentationId; use Behat\Borg\Documentation\Publisher\PublishedDocumentation; +use Behat\Borg\Documentation\Repository\CurrentDocumentationRepository; use Behat\Borg\Package\ReleasePackager; use Behat\Borg\Package\Package; use Behat\Borg\PackageDocumentation\PackagedDocumentationBuilder; @@ -42,7 +43,7 @@ class DocumentationContributorContext implements Context, SnippetAcceptingContex public function __construct() { $this->downloader = new FakeDownloader(); - $repository = new FakeRepository(); + $repository = new CurrentDocumentationRepository(new FakeRepository()); $processor = new BuildingProcessor(new FakeBuilder(), new FakePublisher(), $repository); $this->documentationManager = new Documenter($processor, $repository); diff --git a/features/current_documentation_is_available.feature b/features/current_documentation_is_available.feature index 840d985..449178e 100644 --- a/features/current_documentation_is_available.feature +++ b/features/current_documentation_is_available.feature @@ -15,7 +15,7 @@ Feature: Current documentation is available When I release "Behat/Symfony2Extension" version "v2.0.0" And I release "Behat/Symfony2Extension" version "master" And I release "Behat/Symfony2Extension" version "v1.1.2" - Then current version of "behat/symfony2-extension" documentation should point to version "v2.0.0" + Then current version of "behat/symfony2-extension" documentation should point to version "v2.0" Scenario: Having dev versions published Given "behat/behat" version "v3.0" was documented in "Behat/docs" diff --git a/spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php b/spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php new file mode 100644 index 0000000..9d8ea2f --- /dev/null +++ b/spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php @@ -0,0 +1,89 @@ +beConstructedWith($decoratedRepo); + } + + function it_is_documentation_repository() + { + $this->shouldHaveType(Repository::class); + } + + function it_proxies_save_calls_to_the_decorated_repository( + Repository $decoratedRepo, + BuiltDocumentation $built + ) { + $documentation = PublishedDocumentation::publish($built->getWrappedObject(), '/'); + + $decoratedRepo->save($documentation)->shouldBeCalled(); + + $this->save($documentation); + } + + function it_proxies_findForProject_calls_to_the_decorated_repository( + Repository $decoratedRepo, + BuiltDocumentation $built + ) { + $documentation = PublishedDocumentation::publish($built->getWrappedObject(), '/'); + + $decoratedRepo->findForProject('my/project')->willReturn([$documentation]); + + $this->findForProject('my/project')->shouldReturn([$documentation]); + } + + function it_proxies_call_to_find_if_provided_documentation_id_is_not_current( + Repository $decoratedRepo, + DocumentationId $anId, + BuiltDocumentation $built + ) { + $anId->getVersionString()->willReturn('v2.5'); + $documentation = PublishedDocumentation::publish($built->getWrappedObject(), '/'); + + $decoratedRepo->find($anId)->willReturn($documentation); + + $this->find($anId)->shouldReturn($documentation); + } + + function it_replaces_calls_to_find_current_documentation_with_latest_stable_version_of_project( + Repository $decoratedRepo, + BuiltDocumentation $built1, + BuiltDocumentation $built2, + BuiltDocumentation $built3 + ) { + $built1->getDocumentationId()->willReturn(new ProjectDocumentationId('my/project', 'v1.1.1')); + $built1->getBuildPath()->willReturn(); + $built1->getDocumentationTime()->willReturn(); + $built1->getBuildTime()->willReturn(); + + $built2->getDocumentationId()->willReturn(new ProjectDocumentationId('my/project', 'v2.0.0')); + $built2->getBuildPath()->willReturn(); + $built2->getDocumentationTime()->willReturn(); + $built2->getBuildTime()->willReturn(); + + $built3->getDocumentationId()->willReturn(new ProjectDocumentationId('my/project', 'v1.1.2')); + $built3->getBuildPath()->willReturn(); + $built3->getDocumentationTime()->willReturn(); + $built3->getBuildTime()->willReturn(); + + $doc1 = PublishedDocumentation::publish($built1->getWrappedObject(), '/'); + $doc2 = PublishedDocumentation::publish($built2->getWrappedObject(), '/'); + $doc3 = PublishedDocumentation::publish($built3->getWrappedObject(), '/'); + + $decoratedRepo->findForProject('my/project')->willReturn([$doc1, $doc2, $doc3]); + + $this->find(new ProjectDocumentationId('my/project', 'current'))->shouldReturn($doc2); + } +} diff --git a/spec/Documentation/Repository/CurrentableRepositorySpec.php b/spec/Documentation/Repository/CurrentableRepositorySpec.php new file mode 100644 index 0000000..37ed190 --- /dev/null +++ b/spec/Documentation/Repository/CurrentableRepositorySpec.php @@ -0,0 +1,14 @@ +shouldHaveType('Behat\Borg\Documentation\Repository\CurrentableRepository'); + } +} diff --git a/src/Documentation/Repository/CurrentDocumentationRepository.php b/src/Documentation/Repository/CurrentDocumentationRepository.php new file mode 100644 index 0000000..0623170 --- /dev/null +++ b/src/Documentation/Repository/CurrentDocumentationRepository.php @@ -0,0 +1,66 @@ +decorated = $decoratedRepository; + } + + /** + * {@inheritdoc} + */ + public function save(PublishedDocumentation $documentation) + { + $this->decorated->save($documentation); + } + + /** + * {@inheritdoc} + */ + public function find(DocumentationId $documentationId) + { + if ('current' != $documentationId->getVersionString()) { + return $this->decorated->find($documentationId); + } + + $documentation = $this->findForProject($documentationId->getProjectName()); + usort($documentation, [$this, 'compareVersions']); + + return end($documentation); + } + + /** + * {@inheritdoc} + */ + public function findForProject($projectName) + { + return $this->decorated->findForProject($projectName); + } + + private function compareVersions(PublishedDocumentation $a, PublishedDocumentation $b) + { + $versionA = $a->getDocumentationId()->getVersionString(); + $versionB = $b->getDocumentationId()->getVersionString(); + + return version_compare($versionA, $versionB); + } +} diff --git a/src/Documentation/Repository/CurrentableRepository.php b/src/Documentation/Repository/CurrentableRepository.php new file mode 100644 index 0000000..2bc7cd7 --- /dev/null +++ b/src/Documentation/Repository/CurrentableRepository.php @@ -0,0 +1,7 @@ + Date: Sun, 11 Jan 2015 21:25:55 +0000 Subject: [PATCH 24/37] Wrap FilesystemRepository into CurrentDocumentationRepository --- .../DocumentationBundle/Resources/config/services.xml | 10 +++++++--- src/Documentation/Repository/CurrentableRepository.php | 7 ------- 2 files changed, 7 insertions(+), 10 deletions(-) delete mode 100644 src/Documentation/Repository/CurrentableRepository.php diff --git a/src/Application/DocumentationBundle/Resources/config/services.xml b/src/Application/DocumentationBundle/Resources/config/services.xml index c9c8f99..d1a54fb 100644 --- a/src/Application/DocumentationBundle/Resources/config/services.xml +++ b/src/Application/DocumentationBundle/Resources/config/services.xml @@ -53,9 +53,13 @@ - %documentation.publisher.path%/published.meta + class="Behat\Borg\Documentation\Repository\CurrentDocumentationRepository" + public="false"> + + + %documentation.publisher.path%/published.meta + + Date: Sun, 11 Jan 2015 21:35:37 +0000 Subject: [PATCH 25/37] Move sorting responsibility back to repositories --- .../CurrentDocumentationRepositorySpec.php | 2 +- .../Repository/CurrentableRepositorySpec.php | 14 -------------- .../Documentation/FilesystemRepository.php | 14 +++++++++++++- .../CurrentDocumentationRepository.php | 17 +++-------------- tests/Fake/Documentation/FakeRepository.php | 14 +++++++++++++- 5 files changed, 30 insertions(+), 31 deletions(-) delete mode 100644 spec/Documentation/Repository/CurrentableRepositorySpec.php diff --git a/spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php b/spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php index 9d8ea2f..5bd4109 100644 --- a/spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php +++ b/spec/Documentation/Repository/CurrentDocumentationRepositorySpec.php @@ -84,6 +84,6 @@ function it_replaces_calls_to_find_current_documentation_with_latest_stable_vers $decoratedRepo->findForProject('my/project')->willReturn([$doc1, $doc2, $doc3]); - $this->find(new ProjectDocumentationId('my/project', 'current'))->shouldReturn($doc2); + $this->find(new ProjectDocumentationId('my/project', 'current'))->shouldReturn($doc1); } } diff --git a/spec/Documentation/Repository/CurrentableRepositorySpec.php b/spec/Documentation/Repository/CurrentableRepositorySpec.php deleted file mode 100644 index 37ed190..0000000 --- a/spec/Documentation/Repository/CurrentableRepositorySpec.php +++ /dev/null @@ -1,14 +0,0 @@ -shouldHaveType('Behat\Borg\Documentation\Repository\CurrentableRepository'); - } -} diff --git a/src/Application/Infrastructure/Documentation/FilesystemRepository.php b/src/Application/Infrastructure/Documentation/FilesystemRepository.php index b193b26..2c0862a 100644 --- a/src/Application/Infrastructure/Documentation/FilesystemRepository.php +++ b/src/Application/Infrastructure/Documentation/FilesystemRepository.php @@ -27,16 +27,28 @@ public function find(DocumentationId $documentationId) public function findForProject($projectName) { - return array_filter( + $documentation = array_filter( $this->repo->getAll(), function (PublishedDocumentation $documentation) use ($projectName) { return strtolower($projectName) == $documentation->getDocumentationId()->getProjectName(); } ); + + usort($documentation, [$this, 'compareVersions']); + + return $documentation; } public function getIdentity($object) { return (string)$object->getDocumentationId(); } + + private function compareVersions(PublishedDocumentation $a, PublishedDocumentation $b) + { + $versionA = $a->getDocumentationId()->getVersionString(); + $versionB = $b->getDocumentationId()->getVersionString(); + + return version_compare($versionB, $versionA); + } } diff --git a/src/Documentation/Repository/CurrentDocumentationRepository.php b/src/Documentation/Repository/CurrentDocumentationRepository.php index 0623170..fdaeb58 100644 --- a/src/Documentation/Repository/CurrentDocumentationRepository.php +++ b/src/Documentation/Repository/CurrentDocumentationRepository.php @@ -38,14 +38,11 @@ public function save(PublishedDocumentation $documentation) */ public function find(DocumentationId $documentationId) { - if ('current' != $documentationId->getVersionString()) { - return $this->decorated->find($documentationId); + if ('current' === $documentationId->getVersionString()) { + return current($this->findForProject($documentationId->getProjectName())); } - $documentation = $this->findForProject($documentationId->getProjectName()); - usort($documentation, [$this, 'compareVersions']); - - return end($documentation); + return $this->decorated->find($documentationId); } /** @@ -55,12 +52,4 @@ public function findForProject($projectName) { return $this->decorated->findForProject($projectName); } - - private function compareVersions(PublishedDocumentation $a, PublishedDocumentation $b) - { - $versionA = $a->getDocumentationId()->getVersionString(); - $versionB = $b->getDocumentationId()->getVersionString(); - - return version_compare($versionA, $versionB); - } } diff --git a/tests/Fake/Documentation/FakeRepository.php b/tests/Fake/Documentation/FakeRepository.php index dfa514d..5570ed3 100644 --- a/tests/Fake/Documentation/FakeRepository.php +++ b/tests/Fake/Documentation/FakeRepository.php @@ -29,16 +29,28 @@ public function find(DocumentationId $anId) public function findForProject($projectName) { - return array_filter( + $documentation = array_filter( $this->repository->getAll(), function (PublishedDocumentation $documentation) use ($projectName) { return strtolower($projectName) == $documentation->getDocumentationId()->getProjectName(); } ); + + usort($documentation, [$this, 'compareVersions']); + + return $documentation; } public function getIdentity($object) { return (string)$object->getDocumentationId(); } + + private function compareVersions(PublishedDocumentation $a, PublishedDocumentation $b) + { + $versionA = $a->getDocumentationId()->getVersionString(); + $versionB = $b->getDocumentationId()->getVersionString(); + + return version_compare($versionB, $versionA); + } } From 2a65dd1195209b92730cd2b42f12ecebf7de55c9 Mon Sep 17 00:00:00 2001 From: everzet Date: Sun, 11 Jan 2015 21:40:07 +0000 Subject: [PATCH 26/37] Rewire routes to use `current` instead of hardcoded `v3.0.x` --- app/Resources/views/homepage.html.twig | 4 ++-- app/Resources/views/layout.html.twig | 2 +- app/config/routing.yml | 2 +- .../Controller/DocumentationController.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/Resources/views/homepage.html.twig b/app/Resources/views/homepage.html.twig index 769e5d5..e5b8797 100644 --- a/app/Resources/views/homepage.html.twig +++ b/app/Resources/views/homepage.html.twig @@ -18,10 +18,10 @@