/**
  * Creates and returns an ExtendsOrImplements constraint.
  *
  * @param string[] $parentsAndInterfaces
  *
  * @return ExtendsOrImplements
  * @throws \PHPUnit_Framework_Exception
  */
 public static function extendsOrImplements($parentsAndInterfaces)
 {
     if (!is_array($parentsAndInterfaces)) {
         throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
     }
     return new ExtendsOrImplements($parentsAndInterfaces);
 }
 /**
  * @param  array|ArrayAccess           $value
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($value)
 {
     if (!(is_array($value) || $value instanceof ArrayAccess)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
     }
     $this->value = $value;
 }
Пример #3
0
 /**
  * @param \PHP\Manipulator\Tokenfinder\Result $other
  * @param  string $description Additional information about the test
  * @param  bool $returnResult Whether to return a result or throw an exception
  * @return boolean
  */
 public function evaluate($other, $description = '', $returnResult = FALSE)
 {
     if (!$other instanceof Result) {
         throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'PHP\\Manipulator\\Tokenfinder\\Result');
     }
     $expectedResultTokens = $this->_expectedResult->getTokens();
     $actualResultTokens = $other->getTokens();
     if (count($expectedResultTokens) != count($actualResultTokens)) {
         $this->_cause = 'length';
         if ($returnResult) {
             return FALSE;
         }
         $this->fail($other, $description);
     }
     foreach ($expectedResultTokens as $key => $token) {
         if ($token !== $actualResultTokens[$key]) {
             $this->_cause = 'missmatch of token: ' . $key;
             if ($returnResult) {
                 return FALSE;
             }
             $this->fail($other, $description);
         }
     }
     return true;
 }
Пример #4
0
 /**
  * Defines if should use STDERR redirection or not.
  *
  * Then $stderrRedirection is TRUE, STDERR is redirected to STDOUT.
  *
  * @throws PHPUnit_Framework_Exception
  *
  * @param bool $stderrRedirection
  */
 public function setUseStderrRedirection($stderrRedirection)
 {
     if (!is_bool($stderrRedirection)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'boolean');
     }
     $this->stderrRedirection = $stderrRedirection;
 }
 /** Checks the status code.
  *
  * @param Test_Browser $browser
  *
  * @throws InvalidArgumentException
  * @return bool
  */
 protected function matches($browser)
 {
     if (!$browser instanceof Test_Browser) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(0, 'Test_Browser');
     }
     return $this->_equal === in_array($browser->getResponse()->getStatusCode(), $this->_expected);
 }
 /** Checks the status code.
  *
  * @param sfForm $form
  *
  * @return bool
  */
 protected function matches($form)
 {
     if (!$form instanceof sfForm) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(0, 'Test_Browser');
     }
     return $form->isValid() == $this->_expected;
 }
 /**
  * Creates and returns an DefaultAttributesValues constraint.
  *
  * @param array $defaultAttributes
  *
  * @return DefaultAttributesValues
  * @throws \PHPUnit_Framework_Exception
  */
 public static function defaultAttributesValues($defaultAttributes)
 {
     if (!is_array($defaultAttributes)) {
         throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
     }
     return new DefaultAttributesValues($defaultAttributes);
 }
Пример #8
0
 /**
  * Creates configuration constraint for config object
  *
  * @param Varien_Simplexml_Config $config
  */
 public function __construct($constraint)
 {
     if (!$constraint instanceof Mage_PHPUnit_Constraint_Config_Interface) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'Mage_PHPUnit_Constraint_Config_Interface');
     }
     $this->constraint = $constraint;
 }
Пример #9
0
 public function setOs($os)
 {
     if (!is_string($os)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     $this->os = $os;
 }
Пример #10
0
 /**
  * Creates and returns an UsesTraits constraint.
  *
  * @param string[] $traits
  *
  * @return UsesTraits
  * @throws \PHPUnit_Framework_Exception
  */
 public static function usesTraits($traits)
 {
     if (!is_array($traits)) {
         throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'array or ArrayAccess');
     }
     return new UsesTraits($traits);
 }
Пример #11
0
 /**
  * Constraint for testing observer
  * event definitions in configuration
  *
  * @param string $area
  * @param string $eventName
  * @param string $observerClassAlias
  * @param string $observerMethod
  * @param string|null $observerName
  */
 public function __construct($area, $eventName, $observerClassAlias, $observerMethod, $type = self::TYPE_DEFINDED, $observerName = null)
 {
     if (empty($area) || !is_string($area)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string', $area);
     }
     if (empty($eventName) || !is_string($eventName)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string', $eventName);
     }
     if (empty($observerClassAlias) || !is_string($observerClassAlias)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(3, 'string', $observerClassAlias);
     }
     if (empty($observerMethod) || !is_string($observerMethod)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(4, 'string', $observerMethod);
     }
     if ($observerName !== null && !is_string($observerName)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(6, 'string', $observerName);
     }
     $this->_area = $area;
     $this->_eventName = $eventName;
     $this->_observerClassAlias = $observerClassAlias;
     $this->_observerMethod = $observerMethod;
     $this->_observerName = $observerName;
     $expectedValue = $this->_observerClassAlias . '::' . $this->_observerMethod;
     $nodePath = sprintf(self::XML_PATH_EVENTS, $this->_area, $this->_eventName);
     parent::__construct($nodePath, $type, $expectedValue);
 }
Пример #12
0
 public static function regExp($pattern)
 {
     if (!is_string($pattern)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     return new PHPUnit_Framework_Constraint_PCREMatch($pattern);
 }
Пример #13
0
 /**
  * @param \PHP\Manipulator\Token $other
  * @param  string $description Additional information about the test
  * @param  bool $returnResult Whether to return a result or throw an exception
  * @return boolean
  */
 public function evaluate($other, $description = '', $returnResult = FALSE)
 {
     if (!$other instanceof Token) {
         throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'PHP\\Manipulator\\Token');
     }
     $expectedToken = $this->_expectedToken;
     $equal = $this->_getEqualsConstraint($expectedToken->getValue());
     if (!$equal->evaluate($other->getValue(), $description, true)) {
         $this->_difference = 'values';
         if ($returnResult) {
             return FALSE;
         }
         $this->fail($other, $description);
     }
     $equal = $this->_getEqualsConstraint($expectedToken->getType());
     if (!$equal->evaluate($other->getType(), $description, true)) {
         $this->_difference = 'types';
         if ($returnResult) {
             return FALSE;
         }
         $this->fail($other, $description);
     }
     if (true === $this->_strict) {
         $equal = $this->_getEqualsConstraint($expectedToken->getLinenumber());
         if (!$equal->evaluate($other->getLinenumber(), $description, true)) {
             $this->_difference = 'linenumber';
             if ($returnResult) {
                 return FALSE;
             }
             $this->fail($other, $description);
         }
     }
     return true;
 }
Пример #14
0
 /**
  * @param \PHP\Manipulator\TokenContainer $other
  * @param  string $description Additional information about the test
  * @param  bool $returnResult Whether to return a result or throw an exception
  * @return boolean
  */
 public function evaluate($other, $description = '', $returnResult = FALSE)
 {
     if (!$other instanceof TokenContainer) {
         throw \PHPUnit_Util_InvalidArgumentHelper::factory(1, 'PHP\\Manipulator\\TokenContainer');
     }
     $expectedIterator = $this->_expectedContainer->getIterator();
     $actualIterator = $other->getIterator();
     $i = 0;
     while ($expectedIterator->valid() && $actualIterator->valid()) {
         $expectedToken = $expectedIterator->current();
         /* @var $expectedToken PHP\Manipulator\Token */
         $actualToken = $actualIterator->current();
         /* @var $actualToken PHP\Manipulator\Token */
         if (!$actualToken->equals($expectedToken, $this->_strict)) {
             if ($returnResult) {
                 return FALSE;
             }
             $this->fail($other, $description);
         }
         $i++;
         $expectedIterator->next();
         $actualIterator->next();
     }
     if ($expectedIterator->valid() || $actualIterator->valid()) {
         if ($returnResult) {
             return FALSE;
         }
         $this->fail($other, $description);
     }
     return true;
 }
 /**
  * Constraint constructor
  *
  * @param string $nodePath
  * @param string $type
  * @param mixed $expectedValue
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($nodePath, $type, $expectedValue = null)
 {
     if (empty($nodePath) || !is_string($nodePath)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string', $type);
     }
     $this->_nodePath = $nodePath;
     parent::__construct($type, $expectedValue);
 }
 /**
  * @param  int                         $value
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($value)
 {
     if (!is_int($value)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
     }
     parent::__construct();
     $this->value = $value;
 }
Пример #17
0
 public function __construct($value)
 {
     parent::__construct();
     if (!is_string($value)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     $this->value = $value;
 }
 /**
  * @param  boolean $value
  * @param  mixed   $checkForObjectIdentity
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($value, $checkForObjectIdentity = TRUE)
 {
     if (!is_bool($checkForObjectIdentity)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'boolean');
     }
     $this->checkForObjectIdentity = $checkForObjectIdentity;
     $this->value = $value;
 }
Пример #19
0
 /**
  * @param  callable                    $callback
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($callback)
 {
     if (!is_callable($callback)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'callable');
     }
     parent::__construct();
     $this->callback = $callback;
 }
Пример #20
0
 /**
  * Response header assertion
  *
  * @param string $headerName
  * @param string $type
  * @param PHPUnit_Framework_Constraint $constraint
  */
 public function __construct($headerName, $type, PHPUnit_Framework_Constraint $constraint = null)
 {
     if (empty($headerName) || !is_string($headerName)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string', $headerName);
     }
     $this->_expectedValueValidation += array(self::TYPE_CONSTRAINT => array(true, null, 'PHPUnit_Framework_Constraint'));
     parent::__construct($type, $constraint);
     $this->_headerName = $headerName;
 }
Пример #21
0
 /**
  * @param  PHPUnit_Framework_Test      $test
  * @param  int                         $timesRepeat
  * @param  bool                        $processIsolation
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct(PHPUnit_Framework_Test $test, int $timesRepeat = 1, $processIsolation = false)
 {
     if ($timesRepeat < 1) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'positive integer');
     }
     parent::__construct($test);
     $this->timesRepeat = $timesRepeat;
     $this->processIsolation = $processIsolation;
 }
Пример #22
0
 /**
  * @param  int $expected
  * @param  int $actual
  *
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($expected, $actual)
 {
     if (!is_int($expected)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
     }
     parent::__construct();
     $this->expectedValue = $expected;
     $this->actualValue = $actual;
 }
Пример #23
0
 /**
  * @param  PHPUnit_Framework_Constraint|string
  * @throws PHPUnit_Framework_Constraint
  */
 public function __construct($constraint)
 {
     if (!$constraint instanceof PHPUnit_Framework_Constraint) {
         if (!is_string($constraint)) {
             throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
         }
         $constraint = new PHPUnit_Framework_Constraint_IsEqual($constraint, 0, 10, FALSE, TRUE);
     }
     $this->constraint = $constraint;
 }
Пример #24
0
 /**
  * Constructs a test case with the given filename.
  *
  * @param  string $filename
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct($filename)
 {
     if (!is_string($filename)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
     }
     if (!is_file($filename)) {
         throw new PHPUnit_Framework_Exception(sprintf('File "%s" does not exist.', $filename));
     }
     $this->filename = $filename;
 }
Пример #25
0
 /**
  * Constraint for evaluation of table alias
  *
  * @param string $tableAlias
  * @param string $expectedTableName
  * @param string $type
  */
 public function __construct($tableAlias, $expectedTableName, $type = self::TYPE_TABLE_ALIAS)
 {
     if (!strpos($tableAlias, '/')) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'table alias', $tableAlias);
     }
     list($this->_tableAliasPrefix, $this->_tableAliasName) = explode('/', $tableAlias, 2);
     $this->_expectedValueValidation += array(self::TYPE_TABLE_ALIAS => array(true, 'is_string', 'string'));
     $this->_typesWithDiff[] = self::TYPE_TABLE_ALIAS;
     parent::__construct(self::XML_PATH_MODELS, $type, $expectedTableName);
 }
Пример #26
0
 /**
  * Constraint for checking JSON values
  *
  *
  * @param string $type
  * @param array $expectedValue expected json in array format
  * @param string $matchType
  */
 public function __construct($type, $expectedValue = null, $matchType = self::MATCH_AND)
 {
     if ($expectedValue !== null && (empty($matchType) || !is_string($matchType))) {
         PHPUnit_Util_InvalidArgumentHelper::factory(3, 'string', $matchType);
     }
     $this->_expectedValueValidation += array(self::TYPE_MATCH => array(true, 'is_array', 'array'));
     $this->_typesWithDiff[] = self::TYPE_MATCH;
     parent::__construct($type, $expectedValue);
     $this->_matchType = $matchType;
 }
Пример #27
0
 /**
  * @param  PHPUnit_Framework_Test      $test
  * @param  int                         $timesRepeat
  * @param  bool                        $processIsolation
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct(PHPUnit_Framework_Test $test, $timesRepeat = 1, $processIsolation = false)
 {
     parent::__construct($test);
     if (is_integer($timesRepeat) && $timesRepeat >= 0) {
         $this->timesRepeat = $timesRepeat;
     } else {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'positive integer');
     }
     $this->processIsolation = $processIsolation;
 }
Пример #28
0
 /**
  * Block property constraint
  *
  * @return boolean
  */
 public function __construct($blockName, $propertyName, PHPUnit_Framework_Constraint $constraint, $type = self::TYPE_CONSTRAINT)
 {
     if (empty($blockName) || !is_string($blockName)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string', $blockName);
     }
     if (empty($propertyName) || !is_string($propertyName)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string', $propertyName);
     }
     parent::__construct($type, $constraint);
     $this->_blockName = $blockName;
     $this->_propertyName = $propertyName;
 }
Пример #29
0
 /**
  * Constructs a new TestSuite for .phpt test cases.
  *
  * @param  string $directory
  * @param  array  $options Array with ini settings for the php instance run,
  *                         key being the name if the setting, value the ini value.
  * @throws InvalidArgumentException
  */
 public function __construct($directory, array $options = array())
 {
     if (is_string($directory) && is_dir($directory)) {
         $this->setName($directory);
         $iterator = File_Iterator_Factory::getFileIterator($directory, '.phpt');
         foreach ($iterator as $testFile) {
             $this->addTestFile($testFile->getPathname(), $options);
         }
     } else {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'directory name');
     }
 }
Пример #30
0
 /**
  * Constructs a new TestSuite for .phpt test cases.
  *
  * @param  string                      $directory
  * @throws PHPUnit_Framework_Exception
  */
 public function __construct(string $directory)
 {
     if (!is_dir($directory)) {
         throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'directory name');
     }
     $this->setName($directory);
     $facade = new File_Iterator_Facade();
     $files = $facade->getFilesAsArray($directory, '.phpt');
     foreach ($files as $file) {
         $this->addTestFile($file);
     }
 }