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;
 12: 
 13: /**
 14:  * Message when validation fails.
 15:  *
 16:  * @author Noritaka Horio <holy.shared.design@gmail.com>
 17:  * @copyright Noritaka Horio <holy.shared.design@gmail.com>
 18:  */
 19: class FailedMessage implements Message
 20: {
 21:     /**
 22:      * @var string
 23:      */
 24:     private $message;
 25: 
 26:     /**
 27:      * @param string $message
 28:      */
 29:     public function __construct($message = '')
 30:     {
 31:         $this->message = $message;
 32:     }
 33: 
 34:     /**
 35:      * Append the text to the last.
 36:      *
 37:      * @param mixed $value
 38:      *
 39:      * @return $this
 40:      */
 41:     public function appendText($value)
 42:     {
 43:         $text = $this->stringify($value);
 44:         $this->message = $this->message . $text;
 45: 
 46:         return $this;
 47:     }
 48: 
 49:     /**
 50:      * Append the length space.
 51:      *
 52:      * @param int $length
 53:      *
 54:      * @return $this
 55:      */
 56:     public function appendSpace($length)
 57:     {
 58:         $paddingLength = (int) $length;
 59:         $this->message = $this->message . str_pad('', $paddingLength, ' ');
 60: 
 61:         return $this;
 62:     }
 63: 
 64:     /**
 65:      * Append the value to the last.
 66:      *
 67:      * @param mixed $value
 68:      *
 69:      * @return $this
 70:      */
 71:     public function appendValue($value)
 72:     {
 73:         $appendValue = $this->formatValue($value);
 74:         $this->message = $this->message . $appendValue;
 75: 
 76:         return $this;
 77:     }
 78: 
 79:     /**
 80:      * Append the values to the last.
 81:      *
 82:      * @param array $values
 83:      *
 84:      * @return $this
 85:      */
 86:     public function appendValues(array $values)
 87:     {
 88:         $appendValues = [];
 89: 
 90:         foreach ($values as $value) {
 91:             $appendValues[] = $this->formatValue($value);
 92:         }
 93: 
 94:         $this->message = $this->message . implode(', ', $appendValues);
 95: 
 96:         return $this;
 97:     }
 98: 
 99:     public function concat(FailedMessage $message)
100:     {
101:         $prefix = (string) $this;
102:         $suffix = (string) $message;
103:         $concatenatedMessage = trim($prefix) . "\n" . trim($suffix);
104: 
105:         return static::fromString($concatenatedMessage);
106:     }
107: 
108:     public static function fromString($value)
109:     {
110:         return new self($value);
111:     }
112: 
113:     private function boolToString($value)
114:     {
115:         return $value === true ? 'true' : 'false';
116:     }
117: 
118:     public function __toString()
119:     {
120:         return $this->message;
121:     }
122: 
123:     private function formatValue($value)
124:     {
125:         $text = $this->stringify($value);
126: 
127:         if (is_string($value)) {
128:             $text = "'" . $text . "'";
129:         }
130: 
131:         return $text;
132:     }
133: 
134:     private function stringify($value)
135:     {
136:         $appendValue = $value;
137: 
138:         if (is_null($value)) {
139:             $appendValue = 'null';
140:         } else if (is_bool($value)) {
141:             $appendValue = $this->boolToString($value);
142:         } else if (is_string($value) === false) {
143:             $appendValue = rtrim(print_r($value, true));
144:         }
145: 
146:         return $appendValue;
147:     }
148: }
149: 
Expect API documentation generated by ApiGen