|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace WeAreNeopix\LaravelModelTranslation\Commands; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Console\Command; |
|
6
|
|
|
|
|
7
|
|
|
class TestTranslationExtensions extends Command |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* The name and signature of the console command. |
|
11
|
|
|
* |
|
12
|
|
|
* @var string |
|
13
|
|
|
*/ |
|
14
|
|
|
protected $signature = 'translation:test-extensions |
|
15
|
|
|
{extensions?* : The extensions that should be tested} |
|
16
|
|
|
{--no-database : Defines whether the tests should be performed without access to a database}'; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* The console command description. |
|
20
|
|
|
* |
|
21
|
|
|
* @var string |
|
22
|
|
|
*/ |
|
23
|
|
|
protected $description = 'Test if the registered TranslationManager extensions work in the way they are supposed to.'; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Create a new command instance. |
|
27
|
|
|
* |
|
28
|
|
|
* @return void |
|
|
|
|
|
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct() |
|
31
|
|
|
{ |
|
32
|
|
|
parent::__construct(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Execute the console command. |
|
37
|
|
|
* |
|
38
|
|
|
* @return void |
|
39
|
|
|
*/ |
|
40
|
|
|
public function handle() |
|
41
|
|
|
{ |
|
42
|
|
|
$this->info('Testing custom Translation drivers.'); |
|
43
|
|
|
$drivers = $this->prepareExtensions(); |
|
44
|
|
|
$this->info('These drivers are being tested: '.implode(', ', $drivers)); |
|
45
|
|
|
|
|
46
|
|
|
system($this->makeCommand()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Compose the phpunit command to be ran in order to perform the extension tests. |
|
51
|
|
|
* |
|
52
|
|
|
* @param string|null $extensionToRun |
|
|
|
|
|
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
|
|
protected function makeCommand() |
|
56
|
|
|
{ |
|
57
|
|
|
$phpUnitPath = base_path('vendor/bin/phpunit'); |
|
58
|
|
|
$autoloadPath = base_path('vendor/autoload.php'); |
|
59
|
|
|
$phpunitXmlPath = $this->getPhpunitXmlPath(); |
|
60
|
|
|
$testFilePath = $this->getTestFilePath(); |
|
61
|
|
|
|
|
62
|
|
|
$command = "{$phpUnitPath} --bootstrap {$autoloadPath} --configuration {$phpunitXmlPath} {$testFilePath} "; |
|
63
|
|
|
|
|
64
|
|
|
if ($this->option('no-database') === true) { |
|
65
|
|
|
$command .= '_test_without_database_ '; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
$command .= implode(' ', $this->prepareExtensions()); |
|
69
|
|
|
|
|
70
|
|
|
return $command; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Returns the path to the phpunit.xml configuration file. |
|
75
|
|
|
* |
|
76
|
|
|
* @return string |
|
77
|
|
|
*/ |
|
78
|
|
|
protected function getPhpunitXmlPath() |
|
79
|
|
|
{ |
|
80
|
|
|
return base_path('packages/misa-neopix/laravel-model-translation/tests/extensions/phpunit.xml'); |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Return the path to the file to be tested. |
|
85
|
|
|
* We need to include this file manually |
|
86
|
|
|
* in order to provide driver names that are to |
|
87
|
|
|
* be tested after it. |
|
88
|
|
|
* |
|
89
|
|
|
* @return string |
|
90
|
|
|
*/ |
|
91
|
|
|
protected function getTestFilePath() |
|
92
|
|
|
{ |
|
93
|
|
|
return base_path('packages/misa-neopix/laravel-model-translation/tests/extensions/UserExtensionsTest.php'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
/** |
|
97
|
|
|
* We check if the user has provided any extensions here. |
|
98
|
|
|
* If there are any provided extensions, we will use only |
|
99
|
|
|
* those. |
|
100
|
|
|
* Otherwise, we will fetch all the registered |
|
101
|
|
|
* extensions from the TranslationDriver and |
|
102
|
|
|
* test them all. |
|
103
|
|
|
* |
|
104
|
|
|
* @return array |
|
105
|
|
|
*/ |
|
106
|
|
|
protected function prepareExtensions() |
|
107
|
|
|
{ |
|
108
|
|
|
$specifiedExtensions = $this->argument('extensions'); |
|
109
|
|
|
|
|
110
|
|
|
if (! empty($specifiedExtensions)) { |
|
111
|
|
|
return $specifiedExtensions; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
return $this->getLaravel()['translation']->getRegisteredExtensionNames(); |
|
115
|
|
|
} |
|
116
|
|
|
} |
|
117
|
|
|
|
Adding a
@returnannotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.