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 @@ - + Read quick introduction - + Read the documentation diff --git a/app/Resources/views/layout.html.twig b/app/Resources/views/layout.html.twig index cd3b549..6a4c587 100644 --- a/app/Resources/views/layout.html.twig +++ b/app/Resources/views/layout.html.twig @@ -17,7 +17,7 @@ About - + Documentation Fork us diff --git a/app/config/routing.yml b/app/config/routing.yml index 4f2b063..e0b8cad 100644 --- a/app/config/routing.yml +++ b/app/config/routing.yml @@ -13,5 +13,5 @@ documentation: section: 'documentation' requirements: project: '[\w\-]++\/[\w\-]++' - version: 'master|develop|v\d++\.\d++(?:\.x)?' + version: 'current|master|develop|v\d++\.\d++(?:\.x)?' path: '.*\.html' 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/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/bootstrap/DocumentationContributorContext.php b/features/bootstrap/DocumentationContributorContext.php index a4a0ca7..741e84f 100644 --- a/features/bootstrap/DocumentationContributorContext.php +++ b/features/bootstrap/DocumentationContributorContext.php @@ -2,18 +2,20 @@ use Behat\Behat\Context\Context; use Behat\Behat\Context\SnippetAcceptingContext; +use Behat\Borg\Application\Infrastructure\Documentation\PersistedObjectsRepository; use Behat\Borg\Documentation\Page\PageId; use Behat\Borg\Documentation\ProjectDocumentationId; 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\DocumentationManager; +use Behat\Borg\PackageDocumentation\PackagedDocumentationBuilder; +use Behat\Borg\Documenter; use Behat\Borg\Release\ReleaseDownloader; use Behat\Borg\Release\Repository; use Behat\Borg\Release\Release; use Behat\Borg\Release\Version; use Behat\Borg\ReleaseManager; +use PHPUnit_Framework_Assert as PHPUnit; use Fake\Documentation\FakeBuilder; use Fake\Documentation\FakeDocumentedDownload; use Fake\Documentation\FakePublisher; @@ -21,7 +23,6 @@ use Fake\Documentation\FakeSourceFinder; use Fake\Package\FakePackageFinder; use Fake\Release\FakeDownloader; -use PHPUnit_Framework_Assert as PHPUnit; /** * Describes documentation-related features from the documentation manager context. @@ -30,7 +31,7 @@ class DocumentationContributorContext implements Context, SnippetAcceptingContex { private $downloader; private $releaseManager; - private $documentationManager; + private $documenter; use DocumentationTransformations; @@ -39,18 +40,15 @@ class DocumentationContributorContext implements Context, SnippetAcceptingContex */ public function __construct() { - $publisher = new FakePublisher(); - $sourceFinder = new FakeSourceFinder(); - $packageFinder = new FakePackageFinder(); $this->downloader = new FakeDownloader(); - $builder = new FakeBuilder(); + $repository = new PersistedObjectsRepository(null); + $this->documenter = new Documenter(new FakeBuilder(), new FakePublisher(), $repository); $this->releaseManager = new ReleaseManager(); - $this->documentationManager = new DocumentationManager($builder, $publisher); $releaseDownloader = new ReleaseDownloader($this->downloader); - $releasePackager = new ReleasePackager($packageFinder); - $documentingBuilder = new PackageDocumentationBuilder($sourceFinder, $this->documentationManager); + $releasePackager = new ReleasePackager(new FakePackageFinder()); + $documentingBuilder = new PackagedDocumentationBuilder(new FakeSourceFinder(), $this->documenter); $this->releaseManager->registerListener($releaseDownloader); $releaseDownloader->registerListener($releasePackager); @@ -96,7 +94,7 @@ public function iReleaseRelease(Repository $repository, Version $version) public function releaseDocumentationShouldHaveBeenPublished($project, $versionString) { PHPUnit::assertNotNull( - $this->documentationManager->findPage( + $this->documenter->findPage( new ProjectDocumentationId($project, $versionString), new PageId('index.html') ) ); @@ -108,7 +106,7 @@ public function releaseDocumentationShouldHaveBeenPublished($project, $versionSt public function versionDocumentationShouldNotBePublished($project, $versionString) { PHPUnit::assertNull( - $this->documentationManager->findPage( + $this->documenter->findPage( new ProjectDocumentationId($project, $versionString), new PageId('index.html') ) ); @@ -120,7 +118,7 @@ public function versionDocumentationShouldNotBePublished($project, $versionStrin public function packageNameOfPageShouldBe(PageId $pageId, $project, $versionString, $name) { $documentationId = new ProjectDocumentationId($project, $versionString); - $page = $this->documentationManager->findPage($documentationId, $pageId); + $page = $this->documenter->findPage($documentationId, $pageId); PHPUnit::assertNotNull($page, 'Page not found.'); PHPUnit::assertEquals($name, $page->getProjectName()); @@ -132,12 +130,24 @@ public function packageNameOfPageShouldBe(PageId $pageId, $project, $versionStri public function timeOfPageShouldBe(PageId $pageId, $project, $versionString, DateTimeImmutable $time) { $documentationId = new ProjectDocumentationId($project, $versionString); - $page = $this->documentationManager->findPage($documentationId, $pageId); + $page = $this->documenter->findPage($documentationId, $pageId); PHPUnit::assertNotNull($page, 'Page not found.'); 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->documenter->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 */ @@ -149,7 +159,7 @@ public function documentationVersionShouldBeInTheList($project, $versionString) function (PublishedDocumentation $documentation) { return (string)$documentation->getDocumentationId(); }, - $this->documentationManager->getAvailableDocumentation($project) + $this->documenter->findProjectDocumentation($project) ), 'Documentation for provided version not found in the list.' ); diff --git a/features/bootstrap/DocumentationUIContext.php b/features/bootstrap/DocumentationUIContext.php index e91838f..02961ad 100644 --- a/features/bootstrap/DocumentationUIContext.php +++ b/features/bootstrap/DocumentationUIContext.php @@ -1,5 +1,6 @@ assertSession()->statusCodeEquals(404); } + /** + * @Then current version of :project documentation should point to version :versionString + */ + public function currentVersionOfDocumentationShouldPointToVersion($project, $versionString) + { + $this->visitPath("/docs/$project/current/index.html"); + + $this->assertSession()->elementTextContains('css', '.version.current', $versionString); + } + private function releaseCommand(Repository $repository, Version $version) { return __DIR__ . "/../../app/console release {$repository} {$version} -e=test"; diff --git a/features/bootstrap/Fake/Documentation/FakeBuilder.php b/features/bootstrap/Fake/Documentation/FakeBuilder.php index 8a10b79..3c3c84a 100644 --- a/features/bootstrap/Fake/Documentation/FakeBuilder.php +++ b/features/bootstrap/Fake/Documentation/FakeBuilder.php @@ -3,12 +3,12 @@ namespace 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/features/bootstrap/Fake/Documentation/FakeBuiltDocumentation.php b/features/bootstrap/Fake/Documentation/FakeBuiltDocumentation.php index 14c343c..8b2f143 100644 --- a/features/bootstrap/Fake/Documentation/FakeBuiltDocumentation.php +++ b/features/bootstrap/Fake/Documentation/FakeBuiltDocumentation.php @@ -3,7 +3,7 @@ namespace 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; @@ -19,7 +19,7 @@ public function __construct(Documentation $documentation, DateTimeImmutable $bui public function getDocumentationId() { - return $this->documentation->getId(); + return $this->documentation->getDocumentationId(); } public function getBuildPath() diff --git a/features/bootstrap/Fake/Documentation/FakePublisher.php b/features/bootstrap/Fake/Documentation/FakePublisher.php index 89b95e5..8a63228 100644 --- a/features/bootstrap/Fake/Documentation/FakePublisher.php +++ b/features/bootstrap/Fake/Documentation/FakePublisher.php @@ -3,37 +3,13 @@ namespace 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/features/current_documentation_is_available.feature b/features/current_documentation_is_available.feature new file mode 100644 index 0000000..2af659d --- /dev/null +++ b/features/current_documentation_is_available.feature @@ -0,0 +1,35 @@ +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 + + @critical + 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 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" + 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 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 version of "behat/behat" documentation should point to version "master" 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 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/Documentation/DocumentationSpec.php b/spec/Documentation/RawDocumentationSpec.php similarity index 83% rename from spec/Documentation/DocumentationSpec.php rename to spec/Documentation/RawDocumentationSpec.php index a461fc1..f9a105b 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) { @@ -22,7 +22,7 @@ function let(DocumentationId $anId, DateTimeImmutable $time, Source $source) function it_has_an_id(DocumentationId $anId) { - $this->getId()->shouldReturn($anId); + $this->getDocumentationId()->shouldReturn($anId); } function it_has_a_source(Source $source) diff --git a/spec/DocumentationManagerSpec.php b/spec/DocumenterSpec.php similarity index 56% rename from spec/DocumentationManagerSpec.php rename to spec/DocumenterSpec.php index 63c6fb2..fe73147 100644 --- a/spec/DocumentationManagerSpec.php +++ b/spec/DocumenterSpec.php @@ -4,58 +4,46 @@ use Behat\Borg\Documentation\Builder\Builder; use Behat\Borg\Documentation\Builder\BuiltDocumentation; -use Behat\Borg\Documentation\Documentation; +use Behat\Borg\Documentation\Publisher\Publisher; +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; use Prophecy\Argument; -class DocumentationManagerSpec extends ObjectBehavior +class DocumenterSpec 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_builds_documentation_using_builder_and_publishes_it_using_publisher( + function it_processes_documentation_by_building_and_publishing_it( Builder $builder, DocumentationId $anId, Source $source, BuiltDocumentation $builtDocumentation, - Publisher $publisher + Publisher $publisher, + Repository $repository ) { - $documentation = new Documentation( + $raw = new RawDocumentation( $anId->getWrappedObject(), new \DateTimeImmutable(), $source->getWrappedObject() ); + $published = PublishedDocumentation::publish($builtDocumentation->getWrappedObject(), '/'); - $builder->build($documentation)->willReturn($builtDocumentation); - $publisher->publish($builtDocumentation)->shouldBeCalled(); - - $this->build($documentation); - } - - 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__); + $builder->build($raw)->willReturn($builtDocumentation); + $publisher->publish($builtDocumentation)->willReturn($published); + $repository->save($published)->shouldBeCalled(); - $publisher->findForProject('my/project')->willReturn([$publishedDocumentation]); - - $this->getAvailableDocumentation('my/project')->shouldReturn([$publishedDocumentation]); + $this->process($raw); } - 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 ) { @@ -64,29 +52,30 @@ function it_locates_documentation_file_if_it_is_published_and_file_exists( $built->getDocumentationTime()->willReturn(new \DateTimeImmutable()); $pageId = new PageId(basename(__FILE__)); - $publishedDocumentation = PublishedDocumentation::publish($built->getWrappedObject(), __DIR__); + $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 ) { @@ -95,9 +84,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->findAll('my/project')->willReturn([$publishedDocumentation]); + + $this->findProjectDocumentation('my/project')->shouldReturn([$publishedDocumentation]); + } } diff --git a/spec/Package/Documentation/DocumentationPackageFinderSpec.php b/spec/Package/Documentation/DocumentationPackageFinderSpec.php deleted file mode 100644 index 40bb9e6..0000000 --- a/spec/Package/Documentation/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/Package/Documentation/PackageDocumentationBuilderSpec.php b/spec/Package/Documentation/PackageDocumentationBuilderSpec.php deleted file mode 100644 index 65d06d7..0000000 --- a/spec/Package/Documentation/PackageDocumentationBuilderSpec.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/Package/Documentation/borg.json b/spec/Package/Documentation/borg.json deleted file mode 100644 index 1682a39..0000000 --- a/spec/Package/Documentation/borg.json +++ /dev/null @@ -1,3 +0,0 @@ -{ - "for-package": "behat/behat" -} diff --git a/spec/Package/Documentation/DocumentationPackageSpec.php b/spec/PackageDocumentation/DocumentationPackageSpec.php similarity index 96% rename from spec/Package/Documentation/DocumentationPackageSpec.php rename to spec/PackageDocumentation/DocumentationPackageSpec.php index 1d27cfe..4036ca5 100644 --- a/spec/Package/Documentation/DocumentationPackageSpec.php +++ b/spec/PackageDocumentation/DocumentationPackageSpec.php @@ -1,6 +1,6 @@ redirectToRoute('behat_documentation_page', compact('version', 'path')); } @@ -64,7 +64,7 @@ public function behatDocumentationPageAction($version, $path) * * @return RedirectResponse */ - public function documentationIndexAction($project, $version, $path = 'index.html') + public function documentationIndexAction($project, $version = 'current', $path = 'index.html') { return $this->redirectToRoute('documentation_page', compact('project', 'version', 'path')); } @@ -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); @@ -93,15 +93,15 @@ public function documentationPageAction($project, $version, $path) return $this->render("documentation:{$page}", [ 'page' => $page, - 'allPublished' => $manager->getAvailableDocumentation($project) + 'allPublished' => $manager->findProjectDocumentation($project) ]); } /** - * @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 1eae542..603212b 100644 --- a/src/Application/DocumentationBundle/Resources/config/services.xml +++ b/src/Application/DocumentationBundle/Resources/config/services.xml @@ -20,7 +20,7 @@ + class="Behat\Borg\PackageDocumentation\DocumentationPackageFinder" public="false"/> @@ -34,10 +34,10 @@ - + - + + + + + + %documentation.publisher.path%/published.meta repo = $path ? new FileRepository($path, $this) : new InMemoryRepository($this); + } + + public function save(PublishedDocumentation $documentation) + { + $this->repo->save($documentation); + } + + public function find(DocumentationId $documentationId) + { + if ('current' === $documentationId->getVersionString()) { + return current($this->findAll($documentationId->getProjectName())); + } + + return $this->repo->findById((string)$documentationId); + } + + public function findAll($projectName) + { + $documentation = array_filter( + $this->repo->getAll(), + function (PublishedDocumentation $documentation) use ($projectName) { + return strtolower($projectName) == $documentation->getDocumentationId()->getProjectName(); + } + ); + + usort($documentation, [$this, 'compareDocumentation']); + + return $documentation; + } + + public function getIdentity($object) + { + return (string)$object->getDocumentationId(); + } + + private function compareDocumentation(PublishedDocumentation $a, PublishedDocumentation $b) + { + $versionA = $a->getDocumentationId()->getVersionString(); + $versionB = $b->getDocumentationId()->getVersionString(); + + if ($versionB == 'master' && $versionA == 'develop') { + return 1; + } + if ($versionB == 'develop' && $versionA == 'master') { + return -1; + } + + return version_compare($versionB, $versionA); + } +} 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/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/src/Documentation/Publisher/Publisher.php b/src/Documentation/Publisher/Publisher.php index 418a6e4..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. @@ -15,35 +13,8 @@ interface Publisher * Publishes provided built documentation. * * @param BuiltDocumentation $builtDocumentation - */ - 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); + public function publish(BuiltDocumentation $builtDocumentation); } diff --git a/src/Documentation/Documentation.php b/src/Documentation/RawDocumentation.php similarity index 93% rename from src/Documentation/Documentation.php rename to src/Documentation/RawDocumentation.php index ac5f15b..65274b5 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; @@ -32,7 +32,7 @@ public function __construct(DocumentationId $anId, DateTimeImmutable $time, Sour * * @return DocumentationId */ - public function getId() + public function getDocumentationId() { return $this->anId; } diff --git a/src/Documentation/Repository/Repository.php b/src/Documentation/Repository/Repository.php new file mode 100644 index 0000000..82fe98c --- /dev/null +++ b/src/Documentation/Repository/Repository.php @@ -0,0 +1,37 @@ +publisher = $publisher; $this->builder = $builder; + $this->publisher = $publisher; + $this->repository = $repository; } /** - * 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); + $built = $this->builder->build($documentation); + $published = $this->publisher->publish($built); + $this->repository->save($published); } /** @@ -53,15 +61,14 @@ public function build(Documentation $documentation) * @param DocumentationId $documentationId * @param PageId $pageId * - * @return Page|null + * @return null|Page */ 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; } @@ -70,14 +77,14 @@ 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->publisher->findForProject($projectName); + return $this->repository->findAll($projectName); } } 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 @@ finder = $finder; - $this->manager = $manager; + $this->documenter = $documenter; } /** @@ -50,8 +50,8 @@ public function packageWasDownloaded(PackageDownload $packageDownload) $version = $download->getVersion(); $time = $download->getReleaseTime(); - $anId = new PackageDocumentationId($package, $version); + $anId = new PackagedDocumentationId($package, $version); - $this->manager->build(new Documentation($anId, $time, $source)); + $this->documenter->process(new RawDocumentation($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 @@ getSource(); @@ -54,18 +54,18 @@ public function build(Documentation $documentation) $sourcePath = $source->getPath(); $buildPath = $this->getWritableBuildPath($documentation); - $commandLine = $this->getCommandLine($documentation->getId(), $sourcePath, $buildPath); + $commandLine = $this->getCommandLine($documentation->getDocumentationId(), $sourcePath, $buildPath); $this->executeCommand($commandLine); return new BuiltSphinx( - $documentation->getId(), $documentation->getTime(), new DateTimeImmutable(), $buildPath + $documentation->getDocumentationId(), $documentation->getTime(), new DateTimeImmutable(), $buildPath ); } - private function getWritableBuildPath(Documentation $documentation) + private function getWritableBuildPath(RawDocumentation $documentation) { - $buildPath = $this->buildPath . '/' . $documentation->getId(); + $buildPath = $this->buildPath . '/' . $documentation->getDocumentationId(); $this->filesystem->mkdir($buildPath); return $buildPath; 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)); } } 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); }