File tree Expand file tree Collapse file tree 9 files changed +193
-3
lines changed
tests/php/VersionUpdater/Integration Expand file tree Collapse file tree 9 files changed +193
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace PhelWeb \VersionUpdater ;
6+
7+ use Gacela \Framework \AbstractProvider ;
8+ use Gacela \Framework \Container \Container ;
9+ use Phel \Console \ConsoleFacade ;
10+ use Phel \Shared \Facade \ConsoleFacadeInterface ;
11+
12+ /**
13+ * @method Factory getFactory()
14+ */
15+ final class DependencyProvider extends AbstractProvider
16+ {
17+ public const string FACADE_PHEL_CONSOLE = 'FACADE_PHEL_CONSOLE ' ;
18+
19+ public function provideModuleDependencies (Container $ container ): void
20+ {
21+ $ container ->set (self ::FACADE_PHEL_CONSOLE , function (Container $ container ) {
22+ return $ container ->getLocator ()->get (ConsoleFacade::class);
23+ });
24+ }
25+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace PhelWeb \VersionUpdater ;
6+
7+ use Gacela \Framework \AbstractFacade ;
8+
9+ /**
10+ * @method Factory getFactory()
11+ */
12+ final class Facade extends AbstractFacade
13+ {
14+ public function updateTomlFile (): void
15+ {
16+ $ this ->getFactory ()
17+ ->createPhelVersionUpdater ()
18+ ->update ();
19+ }
20+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace PhelWeb \VersionUpdater ;
6+
7+ use Gacela \Framework \AbstractFactory ;
8+ use Gacela \Framework \Config \Config ;
9+ use Phel \Shared \Facade \ConsoleFacadeInterface ;
10+ use PhelWeb \VersionUpdater \Infrastructure \PhelVersionUpdater ;
11+
12+ /**
13+ * @method Config getConfig()
14+ */
15+ final class Factory extends AbstractFactory
16+ {
17+ public function createPhelVersionUpdater (): PhelVersionUpdater
18+ {
19+ return new PhelVersionUpdater (
20+ $ this ->getPhelConsoleFacade (),
21+ $ this ->getConfigFileLocation (),
22+ );
23+ }
24+
25+ private function getPhelConsoleFacade (): ConsoleFacadeInterface
26+ {
27+ return $ this ->getProvidedDependency (DependencyProvider::FACADE_PHEL_CONSOLE );
28+ }
29+
30+ private function getConfigFileLocation (): string
31+ {
32+ return $ this ->getConfig ()->getAppRootDir () . '/../config.toml ' ;
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace PhelWeb \VersionUpdater \Infrastructure ;
6+
7+ use Phel \Shared \Facade \ConsoleFacadeInterface ;
8+
9+ final readonly class PhelVersionUpdater
10+ {
11+ private const string REGEX_PHEL_VERSION_FINDER = '/^phel_version\s*=\s*"[^"]*"/m ' ;
12+
13+ public function __construct (
14+ private ConsoleFacadeInterface $ consoleFacade ,
15+ private string $ configFile ,
16+ ) {
17+ }
18+
19+ public function update (): void
20+ {
21+ $ configContent = file_get_contents ($ this ->configFile );
22+
23+ $ phelVersion = $ this ->consoleFacade ->getVersion ();
24+ $ updatedContent = preg_replace (
25+ self ::REGEX_PHEL_VERSION_FINDER ,
26+ 'phel_version = " ' . $ phelVersion . '" ' ,
27+ $ configContent
28+ );
29+
30+ if ($ updatedContent !== $ configContent ) {
31+ file_put_contents ($ this ->configFile , $ updatedContent );
32+ }
33+ }
34+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace PhelWebTests \VersionUpdater \Integration ;
6+
7+ use Phel \Shared \Facade \ConsoleFacadeInterface ;
8+ use PhelWeb \VersionUpdater \Infrastructure \PhelVersionUpdater ;
9+ use PHPUnit \Framework \TestCase ;
10+
11+ final class PhelVersionUpdaterTest extends TestCase
12+ {
13+ /** @var false|resource */
14+ private $ file ;
15+
16+ protected function setUp (): void
17+ {
18+ $ this ->file = tmpfile ();
19+ fwrite ($ this ->file , 'phel_version = "v.0.9" ' );
20+ }
21+
22+ protected function tearDown (): void
23+ {
24+ fclose ($ this ->file );
25+ }
26+
27+ public function test_update_phel_version (): void
28+ {
29+ $ consoleFacade = $ this ->createAnonConsoleFacade ();
30+
31+ $ path = stream_get_meta_data ($ this ->file )['uri ' ];
32+ $ phelVersionUpdater = new PhelVersionUpdater ($ consoleFacade , $ path );
33+ $ phelVersionUpdater ->update ();
34+
35+ $ content = file_get_contents ($ path );
36+
37+ $ expected = 'phel_version = "v1.0" ' ;
38+
39+ self ::assertSame ($ expected , $ content );
40+ }
41+
42+ private function createAnonConsoleFacade (): ConsoleFacadeInterface
43+ {
44+ return new class implements ConsoleFacadeInterface {
45+
46+ public function getVersion (): string
47+ {
48+ return 'v1.0 ' ;
49+ }
50+
51+ public function runConsole (): void
52+ {
53+ // ignore
54+ }
55+ };
56+ }
57+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ require __DIR__ . '/../vendor/autoload.php ' ;
6+
7+ use Gacela \Framework \Gacela ;
8+ use Phel \Phel ;
9+ use PhelWeb \VersionUpdater \Facade as VersionUpdaterFacade ;
10+
11+ Gacela::bootstrap (__DIR__ , Phel::configFn ());
12+
13+ $ facade = new VersionUpdaterFacade ();
14+ $ facade ->updateTomlFile ();
Original file line number Diff line number Diff line change 4141 " php build/api-page.php" ,
4242 " php build/api-search.php"
4343 ],
44- "test" : " ./vendor/bin/phpunit"
44+ "test" : " ./vendor/bin/phpunit" ,
45+ "post-install-cmd" : [
46+ " php build/update-phel-version.php"
47+ ],
48+ "post-update-cmd" : [
49+ " php build/update-phel-version.php"
50+ ]
4551 }
4652}
Original file line number Diff line number Diff line change @@ -28,5 +28,5 @@ extra_syntaxes_and_themes = ["syntaxes"]
2828# Put all your custom variables here
2929
3030repo_content_url = " https://github.com/phel-lang/phel-lang.org/blob/master/content/"
31- phel_version = " 0 .23.1"
31+ phel_version = " v0 .23.1"
3232
Original file line number Diff line number Diff line change @@ -52,7 +52,7 @@ <h3>Community</h3>
5252 < div class ="footer-badges ">
5353 < span class ="footer-badge "> PHP 8.3+ Required</ span >
5454 < span class ="footer-badge-separator "> •</ span >
55- < span class ="footer-badge footer-badge-version "> v {{ config.extra.phel_version }}</ span >
55+ < span class ="footer-badge footer-badge-version "> {{ config.extra.phel_version }}</ span >
5656 </ div >
5757 </ div >
5858 </ div >
You can’t perform that action at this time.
0 commit comments