Skip to content

Commit aabfb3c

Browse files
author
paramtamtam
committed
Helpers added
1 parent 08bf46f commit aabfb3c

File tree

5 files changed

+73
-3
lines changed

5 files changed

+73
-3
lines changed

src/AppVersionServiceProvider.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ public function register()
5757

5858
$this->registerBlade();
5959

60+
$this->registerHelpers();
61+
6062
if ($this->app->runningInConsole()) {
6163
$this->registerArtisanCommands();
6264
}
@@ -89,6 +91,20 @@ protected function registerBlade()
8991
Blade::directive('app_version', function () {
9092
return "<?php echo resolve('app.version.manager')->formatted(); ?>";
9193
});
94+
95+
Blade::directive('app_build', function () {
96+
return "<?php echo resolve('app.version.manager')->build(); ?>";
97+
});
98+
}
99+
100+
/**
101+
* Register package helpers.
102+
*
103+
* @return void
104+
*/
105+
protected function registerHelpers()
106+
{
107+
require __DIR__ . '/helpers.php';
92108
}
93109

94110
/**

src/helpers.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
4+
5+
if (! function_exists('app_version')) {
6+
/**
7+
* Returns application version.
8+
*
9+
* @return string
10+
*/
11+
function app_version()
12+
{
13+
return resolve(AppVersionManagerContract::class)->formatted();
14+
}
15+
}
16+
17+
if (! function_exists('app_build')) {
18+
/**
19+
* Returns application build (only) version.
20+
*
21+
* @return string
22+
*/
23+
function app_build()
24+
{
25+
return resolve(AppVersionManagerContract::class)->build();
26+
}
27+
}

tests/BladeRenderTest.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public function testRendering()
2222

2323
view()->addNamespace('stubs', __DIR__ . '/stubs/view');
2424

25-
$rendered = view('stubs::app_version')->render();
26-
27-
$this->assertEquals("Application version: {$manager->formatted()}", $rendered);
25+
$this->assertEquals("Application version: {$manager->formatted()}", view('stubs::app_version')->render());
26+
$this->assertEquals("Build version: {$manager->build()}", view('stubs::app_build')->render());
2827
}
2928
}

tests/HelpersTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace AvtoDev\AppVersion\Tests;
4+
5+
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
6+
7+
/**
8+
* Class HelpersTest.
9+
*/
10+
class HelpersTest extends AbstractTestCase
11+
{
12+
/**
13+
* Test helpers.
14+
*
15+
* @return void
16+
*/
17+
public function testHelpers()
18+
{
19+
/** @var AppVersionManagerContract $manager */
20+
$manager = $this->app->make(AppVersionManagerContract::class);
21+
$manager->setBuild($build = 'pre-alpha2');
22+
23+
$this->assertEquals("1.0.0-{$build}", app_version());
24+
25+
$this->assertEquals("{$build}", app_build());
26+
}
27+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Build version: @app_build()

0 commit comments

Comments
 (0)