Skip to content

Commit

Permalink
Make it easy to update test expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
AD7six committed Feb 3, 2016
1 parent 6a36f60 commit a268687
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/TestSuite/StringCompareTrait.php
Expand Up @@ -14,6 +14,8 @@
*/
namespace Cake\TestSuite;

use Cake\Filesystem\File;

/**
* Compare a string to the contents of a file
*
Expand All @@ -32,6 +34,15 @@ trait StringCompareTrait
*/
protected $_compareBasePath = '';

/**
* Update comparisons to match test changes
*
* Initialized with the env variable UPDATE_TEST_COMPARISON_FILES
*
* @var bool
*/
protected $_updateComparisons = null;

/**
* Compare the result to the contents of the file
*
Expand All @@ -43,6 +54,15 @@ public function assertSameAsFile($path, $result)
{
$path = $this->_compareBasePath . $path;

if ($this->_updateComparisons === null) {
$this->_updateComparisons = env('UPDATE_TEST_COMPARISON_FILES');
}

if ($this->_updateComparisons) {
$file = new File($path, true);
$file->write($result);
}

$expected = file_get_contents($path);
$this->assertTextEquals($expected, $result);
}
Expand Down

0 comments on commit a268687

Please sign in to comment.