Skip to content

Commit

Permalink
Merge pull request #148 from plank/fix-command-tests
Browse files Browse the repository at this point in the history
fix flakey command tests
  • Loading branch information
frasmage committed Oct 5, 2019
2 parents 22bbb48 + 09f2ce8 commit 8f3d356
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 13 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -4,3 +4,4 @@ coverage/
.env
.idea/
.phpunit.result.cache
infection/
4 changes: 0 additions & 4 deletions .travis.yml
Expand Up @@ -13,10 +13,6 @@ script:
- vendor/bin/phpunit --coverage-clover build/logs/clover.xml
after_script:
- php vendor/bin/php-coveralls -v
branches:
only:
- master
- develop
cache:
directories:
- $HOME/.composer/cache
14 changes: 14 additions & 0 deletions infection.json.dist
@@ -0,0 +1,14 @@
{
"timeout": 10,
"source": {
"directories": [
"src"
]
},
"logs": {
"text": "infection\/infection.log"
},
"mutators": {
"@default": true
}
}
2 changes: 2 additions & 0 deletions phpunit.xml
Expand Up @@ -8,6 +8,8 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
executionOrder="random"
resolveDependencies="true"
>
<testsuites>
<testsuite name="Package Test Suite">
Expand Down
2 changes: 0 additions & 2 deletions src/Exceptions/MediaUpload/ConfigurationException.php
Expand Up @@ -28,8 +28,6 @@ public static function unrecognizedSource($source): self
$source = get_class($source);
} elseif (is_resource($source)) {
$source = get_resource_type($source);
} else {
$source = (string)$source;
}

return new static("Could not recognize source, `{$source}` provided.");
Expand Down
6 changes: 3 additions & 3 deletions tests/integration/Commands/ImportMediaCommandTest.php
Expand Up @@ -64,11 +64,12 @@ public function test_it_creates_media_for_unmatched_files_non_recursively()

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

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

public function test_it_updates_existing_media()
{
$this->markTestIncomplete('working locally, sporadically failing in Travis. Need to investigate further.');
$artisan = $this->getArtisan();
$media1 = factory(Media::class)->create([
'disk' => 'tmp',
Expand All @@ -95,7 +95,7 @@ public function test_it_updates_existing_media()
'disk' => 'tmp',
'filename' => 'bar',
'extension' => 'png',
'size' => 8444,
'size' => 7173,
'mime_type' => 'image/png',
'aggregate_type' => 'image'
]);
Expand Down
21 changes: 19 additions & 2 deletions tests/integration/Commands/SyncMediaCommandTest.php
Expand Up @@ -6,15 +6,32 @@ class SyncMediaCommandTest extends TestCase
{
public function test_it_calls_prune_and_install()
{
/** @var SyncMediaCommand $command */
$command = $this->getMockBuilder(SyncMediaCommand::class)
->setMethods(['call', 'option', 'argument'])
->getMock();
$command->expects($this->exactly(2))
->method('call')
->withConsecutive(
[$this->equalTo('media:prune')],
[$this->equalTo('media:import')]
[
$this->equalTo('media:prune'),
[
'disk' => null,
'--directory' => '',
'--non-recursive' => false,
]
],
[
$this->equalTo('media:import'),
[
'disk' => null,
'--directory' => '',
'--non-recursive' => false,
'--force' => false
]
]
);

$command->handle();
}
}
5 changes: 3 additions & 2 deletions tests/integration/MediaUploaderTest.php
Expand Up @@ -301,14 +301,15 @@ public function test_it_can_increment_filename_on_duplicate_files()
$media = factory(Media::class)->make([
'disk' => 'tmp',
'directory' => '',
'filename' => 'plank',
'filename' => 'duplicate',
'extension' => 'png'
]);
$this->seedFileForMedia($media);

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


$this->assertEquals('plank-1', $media->filename);
$this->assertEquals('duplicate-1', $media->filename);
}

public function test_it_uploads_files()
Expand Down

0 comments on commit 8f3d356

Please sign in to comment.