-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use custom Prophecy token to clearly see what's not matched
- Loading branch information
Showing
2 changed files
with
87 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
<?php | ||
/** | ||
* This file is part of the SVN-Buddy library. | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @copyright Alexander Obuhovich <[email protected]> | ||
* @link https://github.com/console-helpers/svn-buddy | ||
*/ | ||
|
||
namespace Tests\ConsoleHelpers\SVNBuddy\ProphecyToken; | ||
|
||
|
||
use Prophecy\Argument\Token\TokenInterface; | ||
|
||
class ProgressBarOutputToken implements TokenInterface | ||
{ | ||
|
||
/** | ||
* Value. | ||
* | ||
* @var string | ||
*/ | ||
private $_value; | ||
|
||
/** | ||
* Creates token for matching to progress bar output. | ||
* | ||
* @param string $output Output. | ||
*/ | ||
public function __construct($output) | ||
{ | ||
$this->_value = $output; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function scoreArgument($argument) | ||
{ | ||
return $this->normalize($argument) === $this->normalize($this->_value) ? 6 : false; | ||
} | ||
|
||
/** | ||
* Normalizes text. | ||
* | ||
* @param string $text Text. | ||
* | ||
* @return string | ||
*/ | ||
protected function normalize($text) | ||
{ | ||
$ret = $text; | ||
|
||
// Ignore the unlimited progress bar on PHP 5.6. | ||
if ( \PHP_VERSION_ID < 70000 ) { | ||
$ret = preg_replace('/\[[>-]+\]/', '[----------------------------]', $ret); | ||
} | ||
|
||
// Ignore memory consumption, because it might vary on different PHP versions. | ||
$ret = preg_replace('#<info>\d+\.\d+ MiB\s+</info>#', '<info>0.0 MiB</info>', $ret); | ||
|
||
// Ignore time consumption, because it might vary on different PHP versions. | ||
$ret = preg_replace('/(<\s+)?\d+(\.\d+)? (sec|min)(s)?([\s]+)?/', '5 min', $ret); | ||
|
||
return $ret; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function isLast() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @inheritDoc | ||
*/ | ||
public function __toString() | ||
{ | ||
return sprintf('progress bar output(%s)', $this->_value); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters