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\config;
12: 
13: use expect\Dictionary;
14: use ReflectionClass;
15: use RuntimeException;
16: use Yosymfony\Toml\Toml;
17: 
18: class ConfigurationLoader
19: {
20:     const REPORTER = '\expect\ResultReporter';
21:     const PACKAGE_REGISTRAR = '\expect\PackageRegistrar';
22: 
23:     public function loadFromFile($file)
24:     {
25:         if (file_exists($file) === false) {
26:             throw new ConfigurationFileNotFoundException("$file not found");
27:         }
28:         $values = Toml::parse($file);
29: 
30:         $defaultConfig = new DefaultConfiguration();
31:         $runtimeConfig = $this->loadFromArray($values);
32: 
33:         return $defaultConfig->merge($runtimeConfig);
34:     }
35: 
36:     public function loadFromArray(array $values)
37:     {
38:         $config = Dictionary::fromArray($values);
39:         $loadedPackages = [];
40:         $loadedReporter = null;
41: 
42:         if ($config->containsKey('packages')) {
43:             $packages = $config->get('packages');
44:             $loadedPackages = $this->createPackages($packages->toArray());
45:         }
46: 
47:         if ($config->containsKey('reporter')) {
48:             $reporter = $config->get('reporter');
49:             $loadedReporter = $this->createReporter($reporter);
50:         }
51: 
52:         return new RuntimeConfiguration($loadedPackages, $loadedReporter);
53:     }
54: 
55:     /**
56:      * Create a few new package registrars
57:      *
58:      * @param array $packages
59:      *
60:      * @return \expect\PackageRegistrar[]
61:      */
62:     private function createPackages(array $packages)
63:     {
64:         $matcherPackages = [];
65: 
66:         foreach ($packages as $package) {
67:             $reflection = new ReflectionClass($package);
68: 
69:             if ($reflection->implementsInterface(self::PACKAGE_REGISTRAR) === false) {
70:                 throw NotAvailableException::createForPackage(self::PACKAGE_REGISTRAR);
71:             }
72:             $matcherPackages[] = $reflection->newInstance();
73:         }
74: 
75:         return $matcherPackages;
76:     }
77: 
78:     /**
79:      * Create a new result reporter
80:      *
81:      * @param string $reporter
82:      *
83:      * @return \expect\ResultReporter
84:      */
85:     private function createReporter($reporter)
86:     {
87:         $reflection = new ReflectionClass($reporter);
88: 
89:         if ($reflection->implementsInterface(self::REPORTER) === false) {
90:             throw NotAvailableException::createForReporter(self::REPORTER);
91:         }
92: 
93:         return $reflection->newInstance();
94:     }
95: }
96: 
Expect API documentation generated by ApiGen