Skip to content

Commit 8f3d356

Browse files
authored
Merge pull request #148 from plank/fix-command-tests
fix flakey command tests
2 parents 22bbb48 + 09f2ce8 commit 8f3d356

File tree

8 files changed

+42
-13
lines changed

8 files changed

+42
-13
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ coverage/
44
.env
55
.idea/
66
.phpunit.result.cache
7+
infection/

.travis.yml

-4
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,6 @@ script:
1313
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
1414
after_script:
1515
- php vendor/bin/php-coveralls -v
16-
branches:
17-
only:
18-
- master
19-
- develop
2016
cache:
2117
directories:
2218
- $HOME/.composer/cache

infection.json.dist

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"timeout": 10,
3+
"source": {
4+
"directories": [
5+
"src"
6+
]
7+
},
8+
"logs": {
9+
"text": "infection\/infection.log"
10+
},
11+
"mutators": {
12+
"@default": true
13+
}
14+
}

phpunit.xml

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11+
executionOrder="random"
12+
resolveDependencies="true"
1113
>
1214
<testsuites>
1315
<testsuite name="Package Test Suite">

src/Exceptions/MediaUpload/ConfigurationException.php

-2
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public static function unrecognizedSource($source): self
2828
$source = get_class($source);
2929
} elseif (is_resource($source)) {
3030
$source = get_resource_type($source);
31-
} else {
32-
$source = (string)$source;
3331
}
3432

3533
return new static("Could not recognize source, `{$source}` provided.");

tests/integration/Commands/ImportMediaCommandTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,12 @@ public function test_it_creates_media_for_unmatched_files_non_recursively()
6464

6565
public function test_it_skips_files_of_unmatched_aggregate_type()
6666
{
67-
$this->markTestIncomplete('working locally, failing in Travis. Need to investigate further.');
6867
$artisan = $this->getArtisan();
6968
$filesystem = app(\Illuminate\Filesystem\FilesystemManager::class);
69+
/** @var \Plank\Mediable\MediaUploader $uploader */
7070
$uploader = app('mediable.uploader');
7171
$uploader->setAllowUnrecognizedTypes(false);
72+
$uploader->setAllowedAggregateTypes(['image']);
7273
$command = new ImportMediaCommand($filesystem, $uploader);
7374

7475
$media = factory(Media::class)->make(['disk' => 'tmp', 'extension' => 'foo', 'mime_type' => 'bar']);
@@ -82,7 +83,6 @@ public function test_it_skips_files_of_unmatched_aggregate_type()
8283

8384
public function test_it_updates_existing_media()
8485
{
85-
$this->markTestIncomplete('working locally, sporadically failing in Travis. Need to investigate further.');
8686
$artisan = $this->getArtisan();
8787
$media1 = factory(Media::class)->create([
8888
'disk' => 'tmp',
@@ -95,7 +95,7 @@ public function test_it_updates_existing_media()
9595
'disk' => 'tmp',
9696
'filename' => 'bar',
9797
'extension' => 'png',
98-
'size' => 8444,
98+
'size' => 7173,
9999
'mime_type' => 'image/png',
100100
'aggregate_type' => 'image'
101101
]);

tests/integration/Commands/SyncMediaCommandTest.php

+19-2
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,32 @@ class SyncMediaCommandTest extends TestCase
66
{
77
public function test_it_calls_prune_and_install()
88
{
9+
/** @var SyncMediaCommand $command */
910
$command = $this->getMockBuilder(SyncMediaCommand::class)
1011
->setMethods(['call', 'option', 'argument'])
1112
->getMock();
1213
$command->expects($this->exactly(2))
1314
->method('call')
1415
->withConsecutive(
15-
[$this->equalTo('media:prune')],
16-
[$this->equalTo('media:import')]
16+
[
17+
$this->equalTo('media:prune'),
18+
[
19+
'disk' => null,
20+
'--directory' => '',
21+
'--non-recursive' => false,
22+
]
23+
],
24+
[
25+
$this->equalTo('media:import'),
26+
[
27+
'disk' => null,
28+
'--directory' => '',
29+
'--non-recursive' => false,
30+
'--force' => false
31+
]
32+
]
1733
);
34+
1835
$command->handle();
1936
}
2037
}

tests/integration/MediaUploaderTest.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -301,14 +301,15 @@ public function test_it_can_increment_filename_on_duplicate_files()
301301
$media = factory(Media::class)->make([
302302
'disk' => 'tmp',
303303
'directory' => '',
304-
'filename' => 'plank',
304+
'filename' => 'duplicate',
305305
'extension' => 'png'
306306
]);
307+
$this->seedFileForMedia($media);
307308

308309
$method->invoke($uploader, $media);
309310

310311

311-
$this->assertEquals('plank-1', $media->filename);
312+
$this->assertEquals('duplicate-1', $media->filename);
312313
}
313314

314315
public function test_it_uploads_files()

0 commit comments

Comments
 (0)