8000 Source a little bit refactored · avto-dev/app-version-laravel@31b471a · GitHub
[go: up one dir, main page]

Skip to content

Commit 31b471a

Browse files
author
paramtamtam
committed
Source a little bit refactored
- Source and tests a little bit refactored - Blade directives use contract instead abstract container bind alias - Abstract tests bootstrapper class removed - PHPUnit HTML coverage report disabled by default ([container errors](laravel/framework#10808) after `composer update --no-interaction --prefer-lowest`)
1 parent 0e82048 commit 31b471a

22 files changed

+82
-184
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ composer.lock
1616
/coverage
1717
.DS_Store
1818
.php_cs.cache
19+
clover-file

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
- Composer dependencies clean-up
88

9+
### Updated
10+
11+
- Source and tests a little bit refactored
12+
- Blade directives use contract instead abstract container bind alia 6D40 s
13+
- Abstract tests bootstrapper class removed
14+
- PHPUnit HTML coverage report disabled by default ([container errors](https://github.com/laravel/framework/issues/10808) after `composer update --no-interaction --prefer-lowest`)
15+
916
## v1.2
1017

1118
### Fixed

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
"name": "avto-dev/app-version-laravel",
33
"description": "Laravel applications versioning",
44
"keywords": [
5-
"some",
6-
"keywords",
7-
"goes",
8-
"here"
5+
"laravel",
6+
"version"
97
],
108
"type": "library",
119
"license": "MIT",

phpunit.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="./tests/bootstrap.php"
2+
<phpunit bootstrap="./tests/Bootstrap/bootstrap.php"
33
backupGlobals="false"
44
backupStaticAttributes="false"
55
colors="true"
@@ -22,7 +22,7 @@
2222
</whitelist>
2323
</filter>
2424
<logging>
25-
<log type="coverage-html" target="./coverage/html"/>
25+
<!--log type="coverage-html" target="./coverage/html"/-->
2626
<log type="coverage-xml" target="./coverage/xml"/>
2727
<log type="coverage-clover" target="./coverage/clover.xml"/>
2828
<log type="coverage-text" target="php://stdout" showUncoveredFiles="false"/>

src/AppVersionFacade.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
use Illuminate\Support\Facades\Facade;
66
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
77

8-
/**
9-
* Class AppVersionFacade.
10-
*/
118
class AppVersionFacade extends Facade
129
{
1310
/**

src/AppVersionManager.php

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
use Illuminate\Filesystem\Filesystem;
77
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
88

9-
/**
10-
* Class AppVersionManager.
11-
*/
129
class AppVersionManager implements AppVersionManagerContract
1310
{
1411
/**
@@ -46,16 +43,16 @@ class AppVersionManager implements AppVersionManagerContract
4643
*/
4744
public function __construct(array $config = [], $use_locking = true)
4845
{
49-
$this->config = array_replace_recursive($this->config, $config);
46+
$this->config = \array_replace_recursive($this->config, $config);
5047

5148
// Make minimalistic normalization/typing for versions values
5249
foreach (['major', 'minor', 'patch'] as $key) {
53-
if (is_int($value = $this->config[$key])) {
50+
if (\is_int($value = $this->config[$key])) {
5451
if ($value < 0) {
5552
$this->config[$key] = 0;
5653
}
5754
} else {
58-
$this->config[$key] = (int) preg_replace('/[^0-9]/', '', (string) $value);
55+
$this->config[$key] = (int) preg_replace('/\D/', '', (string) $value);
5956
}
6057
}
6158

@@ -96,7 +93,9 @@ public function patch()
9693
*/
9794
public function build()
9895
{
99-
if (is_string($from_file = $this->buildStored()) && ! empty($from_file)) {
96+
$from_file = $this->buildStored();
97+
98+
if (\is_string($from_file) && ! empty($from_file)) {
10099
return $from_file;
101100
}
102101

@@ -216,6 +215,8 @@ protected function putIntoFile($file_path, $data)
216215
return $this->files->put($file_path, $data, $this->use_locking) > 0;
217216
}
218217

218+
// @codeCoverageIgnoreStart
219219
return false;
220+
// @codeCoverageIgnoreEnd
220221
}
221222
}

src/AppVersionServiceProvider.php

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,17 @@
22

33
namespace AvtoDev\AppVersion;
44

5-
use Illuminate\Support\Facades\Blade;
65
use Illuminate\Contracts\Foundation\Application;
76
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
87
use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
98

10-
/**
11-
* Class AppVersionServiceProvider.
12-
*/
139
class AppVersionServiceProvider extends IlluminateServiceProvider
1410
{
1511
/**
1612
* Versions manager DI bind alias.
1713< F987 code class="diff-text syntax-highlighted-line">
*/
1814
const VERSION_MANAGER_ALIAS = 'app.version.manager';
1915

20-
/**
21-
* Indicates if loading of the provider is deferred.
22-
*
23-
* @var bool
24-
*/
25-
protected $defer = false;
26-
2716
/**
2817
* Get config root key name.
2918
*
@@ -55,10 +44,10 @@ public function register()
5544

5645
$this->registerAppVersionManager();
5746

58-
$this->registerBlade();
59-
6047
$this->registerHelpers();
6148

49+
$this->registerBlade();
50+
6251
if ($this->app->runningInConsole()) {
6352
$this->registerArtisanCommands();
6453
}
@@ -88,16 +77,19 @@ protected function registerAppVersionManager()
8877
*/
8978
protected function registerBlade()
9079
{
91-
Blade::directive('app_version', function () {
92-
return "<?php echo resolve('app.version.manager')->formatted(); ?>";
80+
/** @var \Illuminate\View\Compilers\BladeCompiler $blade */
81+
$blade = $this->app->make('view')->getEngineResolver()->resolve('blade')->getCompiler();
82+
83+
$blade->directive('app_version', function () {
84+
return "<?php echo resolve('" . AppVersionManagerContract::class . "')->formatted(); ?>";
9385
});
9486

95-
Blade::directive('app_build', function () {
96-
return "<?php echo resolve('app.version.manager')->build(); ?>";
87+
$blade->directive('app_build', function () {
88+
return "<?php echo resolve('" . AppVersionManagerContract::class . "')->build(); ?>";
9789
});
9890

99-
Blade::directive('app_version_hash', function ($length = 6) {
100-
return "<?php echo resolve('app.version.manager')->hashed({$length}); ?>";
91+
$blade->directive('app_version_hash', function ($length = 6) {
92+
return "<?php echo resolve('" . AppVersionManagerContract::class . "')->hashed({$length}); ?>";
10193
});
10294
}
10395

@@ -108,7 +100,7 @@ protected function registerBlade()
108100
*/
109101
protected function registerHelpers()
110102
{
111-
require __DIR__ . '/helpers.php';
103+
require_once __DIR__ . '/helpers.php';
112104
}
113105

114106
/**

src/Commands/VersionCommand.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
use Symfony\Component\Console\Input\InputOption;
77
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
88

9-
/**
10-
* Class VersionCommand.
11-
*/
129
class VersionCommand extends Command
1310
{
1411
/**

src/Contracts/AppVersionManagerContract.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace AvtoDev\AppVersion\Contracts;
44

5-
/**
6-
* Interface AppVersionManagerContract.
7-
*/
85
interface AppVersionManagerContract
96
{
107
/**

tests/AbstractTestCase.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,9 @@
22

33
namespace AvtoDev\AppVersion\Tests;
44

5-
use AvtoDev\AppVersion\AppVersionServiceProvider;
65
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
76

8-
/**
9-
* Class AbstractTestCase.
10-
*/
117
abstract class AbstractTestCase extends BaseTestCase
128
{
13-
use Traits\CreatesApplicationTrait,
14-
Traits\AdditionalAssertsTrait;
15-
16-
/**
17-
* {@inheritdoc}
18-
*/
19-
public function setUp()
20-
{
21-
parent::setUp();
22-
23-
$this->app->register(AppVersionServiceProvider::class);
24-
}
9+
use Traits\CreatesApplicationTrait;
2510
}

tests/AppVersionManagerTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
use AvtoDev\AppVersion\AppVersionManager;
66

7-
/**
8-
* Class AppVersionManagerTest.
9-
*/
107
class AppVersionManagerTest extends AbstractTestCase
118
{
129
/**

tests/AppVersionServiceProviderTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
use AvtoDev\AppVersion\AppVersionServiceProvider;
88
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
99

10-
/**
11-
* Class AppVersionServiceProviderTest.
12-
*/
1310
class AppVersionServiceProviderTest extends AbstractTestCase
1411
{
1512
/**

tests/BladeRenderTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
use AvtoDev\AppVersion\Contracts\AppVersionManagerContract;
66

7-
/**
8-
* Class BladeRenderTest.
9-
*/
107
class BladeRenderTest extends AbstractTestCase
118
{
129
/**

tests/Bootstrap/TestsBootstraper.php

Lines changed: 0 additions & 45 deletions
This file was deleted.

tests/Bootstrap/AbstractTestsBootstraper.php renamed to tests/Bootstrap/TestsBootstrapper.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,14 @@
22

33
namespace AvtoDev\AppVersion\Tests\Bootstrap;
44

5+
use AvtoDev\AppVersion\Tests\Traits\CreatesApplicationTrait;
56
use Exception;
6-
use Illuminate\Support\Str;
77
use Illuminate\Filesystem\Filesystem;
88
use Illuminate\Foundation\Application;
9+
use Illuminate\Support\Str;
910
use Symfony\Component\Console\Output\ConsoleOutput;
10-
use AvtoDev\AppVersion\Tests\Traits\CreatesApplicationTrait;
1111

12-
/**
13-
* Class AbstractTestsBootstraper.
14-
*/
15-
abstract class AbstractTestsBootstraper
12+
class TestsBootstrapper
1613
{
1714
use CreatesApplicationTrait;
1815

@@ -31,6 +28,16 @@ abstract class AbstractTestsBootstraper
3128
*/
3229
protected $files;
3330

31+
/**
32+
* Returns path to the storage storage directory (for tests).
33+
*
34+
* @return string
35+
*/
36+
public static function getStorageDirectoryPath()
37+
{
38+
return __DIR__ . '/../temp/storage';
39+
}
40+
3441
/**
3542
* Constructor.
3643
*
@@ -47,7 +54,7 @@ public function __construct()
4754
// Если метод начинается с подстроки 'boot'
4855
if (Str::startsWith($method_name, static::MAGIC_METHODS_PREFIX)) {
4956
// То вызываем метод, передавая ему на вход массив коллекций (хотя передавать не обязательно)
50-
if (call_user_func_array([$this, $method_name], []) !== true) {
57+
if (\call_user_func_array([$this, $method_name], []) !== true) {
5158
throw new Exception(sprintf(
5259
'Bootstrap method "%s" has non-true result. So, we cannot start tests for this reason',
5360
$method_name
@@ -74,9 +81,35 @@ protected function log($message = null, $style = 'info')
7481
$output = $this->app->make(ConsoleOutput::class);
7582
}
7683

77-
$output->writeln(empty($message)
84+
$output->writeln($message === null
7885
? ''
7986
: sprintf('<%1$s>> Bootstrap:</%1$s> <%2$s>%3$s</%2$s>', 'comment', $style, $message)
8087
);
8188
}
89+
90+
/**
91+
* Make storage directory preparations.
92+
*
93+
* @return bool
94+
*/
95+
protected function bootPrepareStorageDirectory()
96+
{
97+
$this->log('Prepare storage directory');
98+
99+
if ($this->files->isDirectory($storage = static::getStorageDirectoryPath())) {
100+
if ($this->files->deleteDirectory($storage)) {
101+
$this->log('Previous storage directory deleted successfully');
102+
} else {
103+
$this->log(sprintf('Cannot delete directory "%s"', $storage));
104+
105+
return false;
106+
}
107+
} else {
108+
$this->files->makeDirectory($storage, 0755, true);
109+
}
110+
111+
$this->files->copyDirectory(__DIR__ . '/../../vendor/laravel/laravel/storage', $storage);
112+
113+
return true;
114+
}
82115
}

tests/Bootstrap/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<?php
2+
3+
new \AvtoDev\AppVersion\Tests\Bootstrap\TestsBootstrapper;

0 commit comments

Comments
 (0)
0