Overview

Namespaces

  • expect
    • config
    • configurator
    • context
    • factory
    • matcher
      • strategy
    • package
    • registry
    • reporter

Classes

  • expect\config\ConfigurationLoader
  • expect\config\DefaultConfiguration
  • expect\config\RuntimeConfiguration
  • expect\configurator\DefaultConfigurator
  • expect\configurator\FileConfigurator
  • expect\context\DefaultContextFactory
  • expect\context\EvaluateContext
  • expect\Dictionary
  • expect\Expect
  • expect\factory\DefaultMatcherFactory
  • expect\FailedMessage
  • expect\matcher\PatternMatcher
  • expect\matcher\strategy\ArrayInclusionStrategy
  • expect\matcher\strategy\InclusionResult
  • expect\matcher\strategy\StringInclusionStrategy
  • expect\matcher\ToBe
  • expect\matcher\ToBeA
  • expect\matcher\ToBeAbove
  • expect\matcher\ToBeAn
  • expect\matcher\ToBeAnInstanceOf
  • expect\matcher\ToBeArray
  • expect\matcher\ToBeBelow
  • expect\matcher\ToBeBoolean
  • expect\matcher\ToBeEmpty
  • expect\matcher\ToBeFalse
  • expect\matcher\ToBeFalsey
  • expect\matcher\ToBeFloat
  • expect\matcher\ToBeGreaterThan
  • expect\matcher\ToBeInteger
  • expect\matcher\ToBeLessThan
  • expect\matcher\ToBeNull
  • expect\matcher\ToBeString
  • expect\matcher\ToBeTrue
  • expect\matcher\ToBeTruthy
  • expect\matcher\ToBeWithin
  • expect\matcher\ToContain
  • expect\matcher\ToEndWith
  • expect\matcher\ToEqual
  • expect\matcher\ToHaveKey
  • expect\matcher\ToHaveLength
  • expect\matcher\ToMatch
  • expect\matcher\ToPrint
  • expect\matcher\ToStartWith
  • expect\matcher\ToThrow
  • expect\matcher\TruthyMatcher
  • expect\MatcherDictionary
  • expect\MatcherEvaluator
  • expect\MatcherPackage
  • expect\package\DefaultMatcherPackage
  • expect\package\DefaultPackageRegistrar
  • expect\package\MatcherClass
  • expect\package\ReflectionIterator
  • expect\registry\DefaultMatcherRegistry
  • expect\reporter\ExceptionReporter
  • expect\reporter\TextMessageReporter
  • expect\Result

Interfaces

  • expect\Configurable
  • expect\Configuration
  • expect\Configurator
  • expect\Context
  • expect\ContextFactory
  • expect\Evaluator
  • expect\Matcher
  • expect\matcher\ReportableMatcher
  • expect\matcher\strategy\InclusionStrategy
  • expect\MatcherContainer
  • expect\MatcherFactory
  • expect\MatcherRegistry
  • expect\Message
  • expect\PackageRegistrar
  • expect\RegisterablePackage
  • expect\ResultReporter

Traits

  • expect\config\ConfigurableConfiguration
  • expect\matcher\EqualMatcherDelegatable
  • expect\matcher\GreaterThanMatcherDelegatable
  • expect\matcher\LengthMatcherDelegatable
  • expect\matcher\LessThanMatcherDelegatable
  • expect\matcher\TypeMatcherDelegatable
  • expect\MatcherLookupTable

Exceptions

  • expect\config\ConfigurationFileNotFoundException
  • expect\config\NotAvailableException
  • expect\package\ComposerJsonNotFoundException
  • expect\registry\MatcherAlreadyRegisteredException
  • expect\registry\MatcherNotRegisteredException
  • expect\reporter\FailedException

Functions

  • expect\expect
  • Overview
  • Namespace
  • Class
  1: <?php
  2: 
  3: /**
  4:  * This file is part of expect package.
  5:  *
  6:  * (c) Noritaka Horio <holy.shared.design@gmail.com>
  7:  *
  8:  * This source file is subject to the MIT license that is bundled
  9:  * with this source code in the file LICENSE.
 10:  */
 11: namespace expect\matcher;
 12: 
 13: use expect\FailedMessage;
 14: use expect\Matcher;
 15: use expect\matcher\strategy\ArrayInclusionStrategy;
 16: use expect\matcher\strategy\StringInclusionStrategy;
 17: 
 18: /**
 19:  * Verify whether the value is all included.
 20:  *
 21:  * <code>
 22:  * $matcher = new ToContain([ 'foo' ]);
 23:  * $matcher->match('foo'); //return true
 24:  *
 25:  * $matcher = new ToContain([ 'foo', 'bar' ]);
 26:  * $matcher->match('foo'); //return false
 27:  *
 28:  * $matcher = new ToContain([ 1, 2 ]);
 29:  * $matcher->match([ 1, 2 ]); //return true
 30:  * <code>
 31:  *
 32:  * @author Noritaka Horio <holy.shared.design@gmail.com>
 33:  * @copyright Noritaka Horio <holy.shared.design@gmail.com>
 34:  */
 35: final class ToContain implements ReportableMatcher
 36: {
 37:     /**
 38:      * @var string
 39:      */
 40:     private $type;
 41: 
 42:     /**
 43:      * @var mixed
 44:      */
 45:     private $actual;
 46: 
 47:     /**
 48:      * @var \expect\matcher\strategy\InclusionResult
 49:      */
 50:     private $matchResult;
 51: 
 52:     /**
 53:      * @var array
 54:      */
 55:     private $expectValues;
 56: 
 57:     /**
 58:      * @param strng|array $expected
 59:      */
 60:     public function __construct($expected)
 61:     {
 62:         $this->expectValues = is_array($expected) ? $expected : [$expected];
 63:     }
 64: 
 65:     /**
 66:      * {@inheritdoc}
 67:      */
 68:     public function match($actual)
 69:     {
 70:         $this->actual = $actual;
 71: 
 72:         $strategy = $this->createStrategy();
 73:         $this->matchResult = $strategy->match($this->expectValues);
 74: 
 75:         return $this->matchResult->isMatched();
 76:     }
 77: 
 78:     /**
 79:      * {@inheritdoc}
 80:      */
 81:     public function reportFailed(FailedMessage $message)
 82:     {
 83:         $unmatchResults = $this->matchResult->getUnmatchResults();
 84: 
 85:         $message->appendText('Expected ')
 86:             ->appendText($this->type)
 87:             ->appendText(' to contain ')
 88:             ->appendValues($unmatchResults);
 89:     }
 90: 
 91:     /**
 92:      * {@inheritdoc}
 93:      */
 94:     public function reportNegativeFailed(FailedMessage $message)
 95:     {
 96:         $matchResults = $this->matchResult->getMatchResults();
 97: 
 98:         $message->appendText('Expected ')
 99:             ->appendText($this->type)
100:             ->appendText(' not to contain ')
101:             ->appendValues($matchResults);
102:     }
103: 
104:     private function createStrategy()
105:     {
106:         $strategy = null;
107: 
108:         if (is_string($this->actual)) {
109:             $this->type = 'string';
110:             $strategy = new StringInclusionStrategy($this->actual);
111:         } elseif (is_array($this->actual)) {
112:             $this->type = 'array';
113:             $strategy = new ArrayInclusionStrategy($this->actual);
114:         }
115: 
116:         return $strategy;
117:     }
118: }
119: 
Expect API documentation generated by ApiGen