Use VFS for testing

This commit is contained in:
Pig Fang 2017-11-19 12:49:24 +08:00
parent 79038d3c63
commit 2e5c1f7890
4 changed files with 63 additions and 11 deletions

View File

@ -22,7 +22,8 @@
"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*",
"barryvdh/laravel-debugbar": "^2.3",
"league/flysystem-memory": "^1.0"
"league/flysystem-memory": "^1.0",
"mikey179/vfsStream": "1.6.4"
},
"autoload": {
"classmap": [

52
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "77b253a290c0333475877f10d93e8510",
"content-hash": "7cc7aede94ac363755668bb4198c9ca4",
"packages": [
{
"name": "classpreloader/classpreloader",
@ -208,7 +208,7 @@
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/erusev/parsedown/zipball/728952b90a333b5c6f77f06ea9422b94b585878d",
"url": "https://files.phpcomposer.com/files/erusev/parsedown/728952b90a333b5c6f77f06ea9422b94b585878d.zip",
"reference": "728952b90a333b5c6f77f06ea9422b94b585878d",
"shasum": ""
},
@ -2324,7 +2324,7 @@
},
"dist": {
"type": "zip",
"url": "https://packagist.phpcomposer.com/files/doctrine/instantiator/8e884e78f9f0eb1329e445619e04456e64d8051d.zip",
"url": "https://files.phpcomposer.com/files/doctrine/instantiator/8e884e78f9f0eb1329e445619e04456e64d8051d.zip",
"reference": "8e884e78f9f0eb1329e445619e04456e64d8051d",
"shasum": ""
},
@ -2575,6 +2575,52 @@
],
"time": "2017-01-05T08:46:19+00:00"
},
{
"name": "mikey179/vfsStream",
"version": "v1.6.4",
"source": {
"type": "git",
"url": "https://github.com/mikey179/vfsStream.git",
"reference": "0247f57b2245e8ad2e689d7cee754b45fbabd592"
},
"dist": {
"type": "zip",
"url": "https://files.phpcomposer.com/files/mikey179/vfsStream/0247f57b2245e8ad2e689d7cee754b45fbabd592.zip",
"reference": "0247f57b2245e8ad2e689d7cee754b45fbabd592",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "~4.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "1.6.x-dev"
}
},
"autoload": {
"psr-0": {
"org\\bovigo\\vfs\\": "src/main/php"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Frank Kleine",
"homepage": "http://frankkleine.de/",
"role": "Developer"
}
],
"description": "Virtual file system to mock the real file system in unit tests.",
"homepage": "http://vfs.bovigo.org/",
"time": "2016-07-18T14:02:57+00:00"
},
{
"name": "mockery/mockery",
"version": "0.9.9",

View File

@ -203,7 +203,8 @@ gulp.task('zip', () => {
'!vendor/mockery/**',
'!vendor/phpunit/**',
'!vendor/symfony/css-selector/**',
'!vendor/symfony/dom-crawler/**'
'!vendor/symfony/dom-crawler/**',
'!vendor/mikey179/vfsStream/**',
], { dot: true })
.pipe(zip(zipPath))
.pipe(notify('Don\'t forget to compile Sass & ES2015 files before publishing a release!'))

View File

@ -1,5 +1,6 @@
<?php
use org\bovigo\vfs;
use Illuminate\Support\Facades\File;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
@ -12,6 +13,9 @@ class UpdateControllerTest extends TestCase
protected function setUp()
{
parent::setUp();
vfs\vfsStream::setup();
return $this->actAs('admin');
}
@ -22,7 +26,7 @@ class UpdateControllerTest extends TestCase
*/
protected function generateFakeUpdateInfo($version, $is_pre_release = false) {
$time = \Carbon\Carbon::now();
file_put_contents(storage_path('testing/update.json'), json_encode([
file_put_contents(vfs\vfsStream::url('root/update.json'), json_encode([
'app_name' => 'blessing-skin-server',
'latest_version' => $version,
'update_time' => $time->getTimestamp(),
@ -59,11 +63,11 @@ class UpdateControllerTest extends TestCase
->see(trans('admin.update.errors.connection'))
->see(config('app.version'))
->uncheck('check_update')
->type(storage_path('testing/update.json'), 'update_source')
->type(vfs\vfsStream::url('root/update.json'), 'update_source')
->press('submit_update');
$this->assertFalse(option('check_update'));
$this->assertEquals(
storage_path('testing/update.json'),
vfs\vfsStream::url('root/update.json'),
option('update_source')
);
@ -74,7 +78,7 @@ class UpdateControllerTest extends TestCase
->see('test')
->see($time);
file_put_contents(storage_path('testing/update.json'), json_encode([
file_put_contents(vfs\vfsStream::url('root/update.json'), json_encode([
'latest_version' => '4.0.0'
]));
$this->visit('/admin/update')
@ -92,7 +96,7 @@ class UpdateControllerTest extends TestCase
'available' => false
]);
option(['update_source' => storage_path('testing/update.json')]);
option(['update_source' => vfs\vfsStream::url('root/update.json')]);
$this->generateFakeUpdateInfo('4.0.0');
$this->get('/admin/update/check')
->seeJson([
@ -103,7 +107,7 @@ class UpdateControllerTest extends TestCase
public function testDownload()
{
option(['update_source' => storage_path('testing/update.json')]);
option(['update_source' => vfs\vfsStream::url('root/update.json')]);
$this->generateFakeUpdateInfo('0.1.0');
$this->get('/admin/update/download');