Skip to content
Permalink
Browse files

Make it easy to update test expectations

  • Loading branch information...
AD7six committed Feb 3, 2016
1 parent 6a36f60 commit a2686877a3855d14368b56c64a87908179e5ab41
Showing with 20 additions and 0 deletions.
  1. +20 −0 src/TestSuite/StringCompareTrait.php
@@ -14,6 +14,8 @@
*/
namespace Cake\TestSuite;
use Cake\Filesystem\File;
/**
* Compare a string to the contents of a file
*
@@ -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
*
@@ -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);
}

0 comments on commit a268687

Please sign in to comment.
You can’t perform that action at this time.