Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
[zendframework/zendframework#4431] Refactored tests slightly
Browse files Browse the repository at this point in the history
- Was observing test failures due to calling markTestSkipped() inside a
  data provider.
- Created new skipIfBuggyMimeContentType() method to call to skip a test
  if mime_content_type() returns buggy information for zip files
  • Loading branch information
weierophinney committed May 6, 2013
1 parent 575de20 commit d942583
Showing 1 changed file with 39 additions and 22 deletions.
61 changes: 39 additions & 22 deletions test/File/IsCompressedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,29 +45,29 @@ public function basicBehaviorDataProvider()

// Sometimes mime_content_type() gives application/zip and sometimes
// application/x-zip ...
$expectedMimeType = mime_content_type(__DIR__ . '/_files/test.zip');
if (!in_array($expectedMimeType, array('application/zip', 'application/x-zip'))) {
$this->markTestSkipped('mime_content_type exhibits buggy behavior on this system!');
}

$fileUpload = array(
'tmp_name' => $testFile, 'name' => basename($testFile),
'size' => 200, 'error' => 0, 'type' => $expectedMimeType
$expectedMimeType = mime_content_type($testFile);
$fileUpload = array(
'tmp_name' => $testFile,
'name' => basename($testFile),
'size' => 200,
'error' => 0,
'type' => $expectedMimeType,
);

return array(
// Options, isValid Param, Expected value
array(null, $fileUpload, true),
array('zip', $fileUpload, true),
array('test/notype', $fileUpload, false),
array('application/x-zip, application/zip, application/x-tar', $fileUpload, true),
array(null, $fileUpload, true),
array('zip', $fileUpload, true),
array('test/notype', $fileUpload, false),
array(array('application/x-zip, application/zip, application/x-tar'), $fileUpload, true),
array(array('application/x-zip', 'application/zip', 'application/x-tar'), $fileUpload, true),
array(array('zip', 'tar'), $fileUpload, true),
array(array('tar', 'arj'), $fileUpload, false),
array(array('zip', 'tar'), $fileUpload, true),
array(array('tar', 'arj'), $fileUpload, false),
);
}

/**
* @return void
* Skip a test if the file info extension is missing
*/
protected function skipIfNoFileInfoExtension()
{
Expand All @@ -82,6 +82,19 @@ function_exists('mime_content_type') && ini_get('mime_magic.magicfile') &&
}
}

/**
* Skip a test if mime_content_type returns buggy information
*/
protected function skipIfBuggyMimeContentType()
{
// Sometimes mime_content_type() gives application/zip and sometimes
// application/x-zip ...
$expectedMimeType = mime_content_type(__DIR__ . '/_files/test.zip');
if (!in_array($expectedMimeType, array('application/zip', 'application/x-zip'))) {
$this->markTestSkipped('mime_content_type exhibits buggy behavior on this system!');
}
}

/**
* Ensures that the validator follows expected behavior
*
Expand All @@ -91,6 +104,7 @@ function_exists('mime_content_type') && ini_get('mime_magic.magicfile') &&
public function testBasic($options, $isValidParam, $expected)
{
$this->skipIfNoFileInfoExtension();
$this->skipIfBuggyMimeContentType();

$validator = new File\IsCompressed($options);
$validator->enableHeaderCheck();
Expand All @@ -101,17 +115,20 @@ public function testBasic($options, $isValidParam, $expected)
* Ensures that the validator follows expected behavior for legacy Zend\Transfer API
*
* @dataProvider basicBehaviorDataProvider
* @return void
*/
public function testLegacy($options, $isValidParam, $expected)
{
if (is_array($isValidParam)) {
$this->skipIfNoFileInfoExtension();

$validator = new File\IsCompressed($options);
$validator->enableHeaderCheck();
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
if (!is_array($isValidParam)) {
// nothing to test
return;
}

$this->skipIfNoFileInfoExtension();
$this->skipIfBuggyMimeContentType();

$validator = new File\IsCompressed($options);
$validator->enableHeaderCheck();
$this->assertEquals($expected, $validator->isValid($isValidParam['tmp_name'], $isValidParam));
}

/**
Expand Down

0 comments on commit d942583

Please sign in to comment.