Download plugins in setUp function

This commit is contained in:
Pig Fang 2017-11-17 07:54:39 +08:00
parent a413927980
commit 6cd5fce271
3 changed files with 20 additions and 58 deletions

View File

@ -20,7 +20,6 @@ before_script:
- mysql -e 'CREATE DATABASE IF NOT EXISTS test;'
- php artisan key:random
- php artisan salt:random
- php -f ./tests/scripts/download-plugins.php
script: ./vendor/bin/phpunit

View File

@ -11,6 +11,26 @@ class PluginControllerTest extends TestCase
protected function setUp()
{
parent::setUp();
$plugins = [
'example-plugin' => 'example-plugin_v1.0.zip',
'avatar-api' => 'avatar-api_v1.1.zip'
];
foreach ($plugins as $plugin_name => $filename) {
if (!file_exists(base_path('plugins/'.$plugin_name))) {
file_put_contents(
storage_path('testing/'.$filename),
file_get_contents("https://github.com/printempw/blessing-skin-plugins/raw/master/dist/$filename")
);
$zip = new ZipArchive();
$zip->open(storage_path('testing/'.$filename));
$zip->extractTo(base_path('plugins/'));
$zip->close();
unlink(storage_path('testing/'.$filename));
}
}
return $this->actAs('admin');
}

View File

@ -1,57 +0,0 @@
<?php
function success($message) {
return "\e[32m$message\e[0m\n";
}
function warning($message) {
return "\e[33m$message\e[0m\n";
}
function error($message) {
return "\e[31m$message\e[0m\n";
}
function getPlugin($plugin_name, $filename) {
if (!file_exists('./plugins/'.$plugin_name)) {
fwrite(STDOUT, warning("Cannot find plugin: $plugin_name"));
fwrite(STDOUT, "Downloading $plugin_name...\n");
$timer = microtime(true);
try {
file_put_contents(
'./storage/'.$filename,
file_get_contents("https://github.com/printempw/blessing-skin-plugins/raw/master/dist/$filename")
);
} catch (Exception $e) {
fwrite(STDOUT, error("Failed to download plugin: $plugin_name."));
exit(1);
}
fwrite(STDOUT, success("Download plugin \"$plugin_name\" successfully."));
fwrite(STDOUT, "Unzipping...\n");
try {
$zip = new ZipArchive();
$zip->open('./storage/'.$filename);
$zip->extractTo('./plugins/');
$zip->close();
unlink('./storage/'.$filename);
} catch (Exception $e) {
fwrite(STDOUT, error("Failed to unzip!"));
exit(1);
}
$time_diff = round(microtime(true) - $timer, 3);
fwrite(STDOUT, success("Finished: \"$plugin_name\" in {$time_diff}s"));
} else {
fwrite(STDOUT, success("Plugin \"$plugin_name\" is existed. OK."));
}
}
$plugins = [
'example-plugin' => 'example-plugin_v1.0.zip',
'avatar-api' => 'avatar-api_v1.1.zip'
];
foreach ($plugins as $plugin_name => $filename) {
getPlugin($plugin_name, $filename);
}