Skip to content

Commit 251a929

Browse files
committed
update unit test.
1 parent 4f665c8 commit 251a929

10 files changed

+125
-115
lines changed

.php_cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
$header = <<<EOF
3+
This file is part of ibrand/laravel-miniprogram-poster.
4+
5+
(c) iBrand <https://www.ibrand.cc>
6+
7+
For the full copyright and license information, please view the LICENSE
8+
file that was distributed with this source code.
9+
EOF;
10+
return PhpCsFixer\Config::create()
11+
->setRiskyAllowed(true)
12+
->setRules(array(
13+
'@Symfony' => true,
14+
'header_comment' => array('header' => $header),
15+
'array_syntax' => array('syntax' => 'short'),
16+
'ordered_imports' => true,
17+
'no_useless_else' => true,
18+
'no_useless_return' => true,
19+
'php_unit_construct' => true,
20+
'php_unit_strict' => true,
21+
))
22+
->setFinder(
23+
PhpCsFixer\Finder::create()
24+
->exclude('vendor')
25+
->in(__DIR__)
26+
)
27+
;

.travis.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
language: php
2+
3+
php:
4+
# using major version aliases
5+
6+
# aliased to a recent 7.x version
7+
- 7.0
8+
# aliased to a recent 7.x version
9+
- 7.1
10+
# aliased to a recent 7.x version
11+
- 7.2
12+
13+
14+
before_script:
15+
- composer self-update
16+
- composer install --prefer-source --no-interaction --dev

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 https://www.ibrand.cc
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

composer.json

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,48 @@
11
{
2-
"name": "ibrand/phantommagick",
2+
"name": "ibrand/laravel-miniprogram-poster",
33
"type": "library",
4-
"description": "ibrand component phantommagick",
4+
"description": "iBrand's laravel miniprogram poster tool",
55
"keywords": [
66
"ibrand",
77
"component",
8-
"phantommagick"
8+
"miniprogram",
9+
"poster"
910
],
1011
"license": "MIT",
1112
"authors": [
1213
{
1314
"name": "tangqi",
14-
"email": "[email protected]"
15+
"email": "[email protected]"
1516
}
1617
],
1718
"require": {
1819
"php": ">=7.0",
19-
"laravel/framework": "5.5.*",
2020
"anam/phantommagick": "dev-docker",
21-
"anam/phantomjs-linux-x86-binary": "^2.1"
21+
"anam/phantomjs-linux-x86-binary": "~2.1.1"
2222
},
2323
"require-dev": {
24-
"mockery/mockery": "dev-master",
2524
"phpunit/phpunit": "~6.0",
2625
"orchestra/testbench": "~3.5",
2726
"orchestra/database": "~3.5"
2827
},
2928
"autoload": {
3029
"psr-4": {
31-
"iBrand\\Poster\\": "src/"
30+
"iBrand\\Miniprogram\\Poster\\": "src/"
3231
}
3332
},
3433
"autoload-dev": {
3534
"psr-4": {
36-
"iBrand\\Poster\\Test\\": "tests/"
35+
"iBrand\\Miniprogram\\Poster\\Test\\": "tests/"
3736
}
3837
},
3938
"extra": {
4039
"laravel": {
4140
"providers": [
42-
"iBrand\\Poster\\PhantoMmagickServiceProvider"
43-
],
44-
"aliases": {
45-
"Converter": "Anam\\PhantomMagick\\Facades\\Converter"
46-
}
41+
"iBrand\\Miniprogram\\Poster\\PhantoMmagickServiceProvider"
42+
]
4743
}
4844
},
4945
"repositories": [
50-
{
51-
"packagist": false
52-
},
53-
{
54-
"type": "composer",
55-
"url": "https://packagist.laravel-china.org"
56-
},
5746
{
5847
"type": "vcs",
5948
"url": "https://github.com/ibrandcc/phantommagick"

scrutinizer.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
checks:
2+
php:
3+
code_rating: true
4+
duplication: true
5+
6+
tools:
7+
# external_code_coverage: true
8+
php_mess_detector: true
9+
php_code_sniffer: true
10+
sensiolabs_security_checker: true
11+
# php_code_coverage: true
12+
php_pdepend: true
13+
php_loc:
14+
enabled: true
15+
excluded_dirs: [vendor, tests]
16+
filter:
17+
excluded_paths:
18+
- 'tests/*'
19+
20+
build:
21+
dependencies:
22+
before:
23+
- composer install
24+
tests:
25+
override:
26+
-
27+
command: vendor/bin/phpunit --coverage-clover=my-coverage-file
28+
coverage:
29+
file: my-coverage-file
30+
format: clover

src/MiniProgramShareImg.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?php
22

3-
namespace iBrand\Poster;
3+
namespace iBrand\Miniprogram\Poster;
44

55
use Anam\PhantomMagick\Converter;
6-
use Illuminate\Support\Facades\Storage;
6+
use Storage;
77

88
class MiniProgramShareImg
99
{
@@ -25,25 +25,26 @@ public static function generateShareImage($route)
2525
}
2626

2727
$options = [
28-
'dimension' => config('phantommagick.width', '575px'),
29-
'zoomfactor' => config('phantommagick.zoomfactor', 1.5),
30-
'quality' => config('phantommagick.quality', 100),
28+
'dimension' => config('ibrand.miniprogram-poster.width', '575px'),
29+
'zoomfactor' => config('ibrand.miniprogram-poster.zoomfactor', 1.5),
30+
'quality' => config('ibrand.miniprogram-poster.quality', 100),
3131
];
3232

33-
$saveName = config('phantommagick.directory') . '/' . md5(uniqid()) . '.png';
34-
$root = config('phantommagick.disks.MiniProgramShare.root');
33+
$saveName = config('ibrand.miniprogram-poster.directory') . '/' . md5(uniqid()) . '.png';
34+
$root = config('ibrand.miniprogram-poster.disks.MiniProgramShare.root');
3535
$file = $root . '/' . $saveName;
3636

3737
try {
3838
$converter = self::init();
3939

4040
$converter->source($route)->toPng($options)->save($file);
4141

42-
if (config('phantommagick.compress', true)) {
42+
if (config('ibrand.miniprogram-poster.compress', true)) {
4343
self::imagePngSizeAdd($file);
4444
}
4545

4646
return Storage::disk('MiniProgramShare')->url($saveName);
47+
4748
} catch (\Exception $exception) {
4849

4950
return false;
@@ -60,7 +61,7 @@ public static function imagePngSizeAdd($file)
6061
$resource = imagecreatetruecolor($new_width, $new_height);
6162
$image = imagecreatefrompng($file);
6263
imagecopyresampled($resource, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
63-
imagejpeg($resource, $file, config('phantommagick.quality'));
64+
imagejpeg($resource, $file, config('ibrand.miniprogram-poster.quality'));
6465
imagedestroy($resource);
6566
}
6667
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace iBrand\Poster;
3+
namespace iBrand\Miniprogram\Poster;
44

55
use Illuminate\Support\ServiceProvider;
66

@@ -9,14 +9,14 @@ class PhantoMmagickServiceProvider extends ServiceProvider
99
public function boot()
1010
{
1111
if ($this->app->runningInConsole()) {
12-
$this->publishes([__DIR__ . '/../config/config.php' => config_path('phantommagick.php')], 'config');
12+
$this->publishes([__DIR__ . '/../config/config.php' => config_path('ibrand/miniprogram-poster.php')], 'config');
1313
}
1414
}
1515

1616
public function register()
1717
{
1818
$filesystems = $this->app['config']->get('filesystems.disks', []);
1919

20-
$this->app['config']->set('filesystems.disks', array_merge(config('phantommagick.disks', []), $filesystems));
20+
$this->app['config']->set('filesystems.disks', array_merge(config('ibrand.miniprogram-poster.disks', []), $filesystems));
2121
}
2222
}

tests/BaseTest.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
abstract class BaseTest extends TestCase
99
{
10-
use DatabaseMigrations;
1110

1211
/**
1312
* set up test.
@@ -16,27 +15,18 @@ protected function setUp()
1615
{
1716
parent::setUp();
1817

19-
$this->loadMigrationsFrom(__DIR__ . '/database');
2018
}
2119

2220
/**
2321
* @param \Illuminate\Foundation\Application $app
2422
*/
2523
protected function getEnvironmentSetUp($app)
2624
{
27-
// Setup default database to use sqlite :memory:
28-
$app['config']->set('database.default', 'testing');
29-
$app['config']->set('database.connections.testing', [
30-
'driver' => 'sqlite',
31-
'database' => ':memory:',
32-
]);
33-
$app['config']->set('repository.cache.enabled', true);
3425

35-
$shareConfig = require __DIR__ . '/config/phantommagick.php';
26+
$app['config']->set('ibrand.miniprogram-poster', require __DIR__.'/../config/config.php');
3627

37-
$app['config']->set('phantommagick', $shareConfig);
3828

39-
$app['config']->set('filesystems.disks', array_merge($shareConfig['disks'], $app['config']->get('filesystems.disks')));
29+
$app['config']->set('filesystems.disks', $app['config']->get('ibrand.miniprogram-poster.disks'), $app['config']->get('filesystems.disks'));
4030
}
4131

4232
/**
@@ -47,8 +37,7 @@ protected function getEnvironmentSetUp($app)
4737
protected function getPackageProviders($app)
4838
{
4939
return [
50-
\Orchestra\Database\ConsoleServiceProvider::class,
51-
\iBrand\Poster\PhantoMmagickServiceProvider::class,
40+
\iBrand\Miniprogram\Poster\PhantoMmagickServiceProvider::class,
5241
];
5342
}
5443
}

tests/MiniProgramShareImgTest.php

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

tests/ShareImgTest.php

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

33
namespace iBrand\Poster\Test;
44

5+
use iBrand\Miniprogram\Poster\MiniProgramShareImg;
6+
use Storage;
7+
58
class ShareImgTest extends BaseTest
69
{
710
/** @test */
@@ -17,7 +20,7 @@ public function TestGenerateShareImage()
1720
{
1821
$route = 'https://m.baidu.com/';
1922

20-
$file = MiniProgramShareImgTest::generateShareImage($route);
21-
$this->assertTrue(file_exists(__DIR__ . '/' . $file));
23+
$url = MiniProgramShareImg::generateShareImage($route);
24+
$this->assertTrue(Storage::disk('MiniProgramShare')->exists($url));
2225
}
2326
}

0 commit comments

Comments
 (0)