| 
 | 1 | +<?php  | 
 | 2 | + | 
 | 3 | +namespace Matthias\SymfonyConfigTest\PhpUnit;  | 
 | 4 | + | 
 | 5 | +/**  | 
 | 6 | + * Extend your test case from this abstract class to test a class that implements  | 
 | 7 | + * Symfony\Component\Config\Definition\ConfigurationInterface  | 
 | 8 | + *  | 
 | 9 | + * @deprecated only use this class if you're still running php 5.3. Use  | 
 | 10 | + * Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait instead  | 
 | 11 | + */  | 
 | 12 | +abstract class AbstractConfigurationTestCase extends \PHPUnit_Framework_TestCase  | 
 | 13 | +{  | 
 | 14 | +    /**  | 
 | 15 | +     * Return the instance of ConfigurationInterface that should be used by the  | 
 | 16 | +     * Configuration-specific assertions in this test-case  | 
 | 17 | +     *  | 
 | 18 | +     * @return \Symfony\Component\Config\Definition\ConfigurationInterface  | 
 | 19 | +     */  | 
 | 20 | +    abstract protected function getConfiguration();  | 
 | 21 | + | 
 | 22 | +    /**  | 
 | 23 | +     * Assert that the given configuration values are invalid.  | 
 | 24 | +     *  | 
 | 25 | +     * Optionally provide (part of) the exception message that you expect to receive.  | 
 | 26 | +     *  | 
 | 27 | +     * When running PHPUnit >=4.3.0, you need to set useRegExp to true if you'd like  | 
 | 28 | +     * to match the exception message using a regular expression.  | 
 | 29 | +     *  | 
 | 30 | +     * @param array $configurationValues  | 
 | 31 | +     * @param string|null $expectedMessage  | 
 | 32 | +     * @param bool $useRegExp  | 
 | 33 | +     */  | 
 | 34 | +    protected function assertConfigurationIsInvalid(array $configurationValues, $expectedMessage = null, $useRegExp = false)  | 
 | 35 | +    {  | 
 | 36 | +        \PHPUnit_Framework_TestCase::assertThat(  | 
 | 37 | +            $configurationValues,  | 
 | 38 | +            new ConfigurationValuesAreInvalidConstraint(  | 
 | 39 | +                $this->getConfiguration(),  | 
 | 40 | +                $expectedMessage,  | 
 | 41 | +                $useRegExp  | 
 | 42 | +            )  | 
 | 43 | +        );  | 
 | 44 | +    }  | 
 | 45 | + | 
 | 46 | +    /**  | 
 | 47 | +     * Assert that the given configuration values are invalid.  | 
 | 48 | +     *  | 
 | 49 | +     * Optionally provide (part of) the exception message that you expect to receive.  | 
 | 50 | +     *  | 
 | 51 | +     * When running PHPUnit >=4.3.0, you need to set useRegExp to true if you'd like  | 
 | 52 | +     * to match the exception message using a regular expression.  | 
 | 53 | +     *  | 
 | 54 | +     * @param array $configurationValues  | 
 | 55 | +     * @param string $breadcrumbPath The path that should be validated, e.g. "doctrine.orm"  | 
 | 56 | +     * @param string|null $expectedMessage  | 
 | 57 | +     * @param bool $useRegExp  | 
 | 58 | +     */  | 
 | 59 | +    protected function assertPartialConfigurationIsInvalid(  | 
 | 60 | +        array $configurationValues,  | 
 | 61 | +        $breadcrumbPath,  | 
 | 62 | +        $expectedMessage = null,  | 
 | 63 | +        $useRegExp = false  | 
 | 64 | +    ) {  | 
 | 65 | +        \PHPUnit_Framework_TestCase::assertThat(  | 
 | 66 | +            $configurationValues,  | 
 | 67 | +            new ConfigurationValuesAreInvalidConstraint(  | 
 | 68 | +                $this->getConfiguration(),  | 
 | 69 | +                $expectedMessage,  | 
 | 70 | +                $useRegExp,  | 
 | 71 | +                $breadcrumbPath  | 
 | 72 | +            )  | 
 | 73 | +        );  | 
 | 74 | +    }  | 
 | 75 | + | 
 | 76 | +    /**  | 
 | 77 | +     * Assert that the given configuration values are valid.  | 
 | 78 | +     *  | 
 | 79 | +     * Optionally provide the part of the configuration that you want to test, e.g. "doctrine.orm"  | 
 | 80 | +     *  | 
 | 81 | +     * @param array $configurationValues  | 
 | 82 | +     * @param string|null $breadcrumbPath  | 
 | 83 | +     */  | 
 | 84 | +    protected function assertConfigurationIsValid(array $configurationValues, $breadcrumbPath = null)  | 
 | 85 | +    {  | 
 | 86 | +        \PHPUnit_Framework_TestCase::assertThat(  | 
 | 87 | +            $configurationValues,  | 
 | 88 | +            new ConfigurationValuesAreValidConstraint(  | 
 | 89 | +                $this->getConfiguration(),  | 
 | 90 | +                $breadcrumbPath  | 
 | 91 | +            )  | 
 | 92 | +        );  | 
 | 93 | +    }  | 
 | 94 | + | 
 | 95 | +    /**  | 
 | 96 | +     * Assert that the given configuration values, when processed, will equal to the given array.  | 
 | 97 | +     *  | 
 | 98 | +     * Optionally provide the part of the configuration that you want to test, e.g. "doctrine.orm"  | 
 | 99 | +     *  | 
 | 100 | +     * @param array $configurationValues  | 
 | 101 | +     * @param array $expectedProcessedConfiguration  | 
 | 102 | +     * @param string|null $breadcrumbPath  | 
 | 103 | +     */  | 
 | 104 | +    protected function assertProcessedConfigurationEquals(  | 
 | 105 | +        array $configurationValues,  | 
 | 106 | +        array $expectedProcessedConfiguration,  | 
 | 107 | +        $breadcrumbPath = null  | 
 | 108 | +    ) {  | 
 | 109 | +        \PHPUnit_Framework_TestCase::assertThat(  | 
 | 110 | +            $expectedProcessedConfiguration,  | 
 | 111 | +            new ProcessedConfigurationEqualsConstraint(  | 
 | 112 | +                $this->getConfiguration(),  | 
 | 113 | +                $configurationValues,  | 
 | 114 | +                $breadcrumbPath  | 
 | 115 | +            )  | 
 | 116 | +        );  | 
 | 117 | +    }  | 
 | 118 | +}  | 
0 commit comments