|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Matthias\SymfonyConfigTest\Tests; |
| 4 | + |
| 5 | +use Matthias\SymfonyConfigTest\PhpUnit\ConfigurationTestCaseTrait; |
| 6 | +use Matthias\SymfonyConfigTest\Tests\PhpUnit\Fixtures\ConfigurationWithRequiredValue; |
| 7 | + |
| 8 | +class ConfigurationTestCaseTraitTest extends \PHPUnit_Framework_TestCase |
| 9 | +{ |
| 10 | + use ConfigurationTestCaseTrait; |
| 11 | + |
| 12 | + protected function getConfiguration() |
| 13 | + { |
| 14 | + return new ConfigurationWithRequiredValue(); |
| 15 | + } |
| 16 | + |
| 17 | + /** |
| 18 | + * @test |
| 19 | + */ |
| 20 | + public function it_can_assert_that_a_configuration_is_invalid() |
| 21 | + { |
| 22 | + $this->assertConfigurationIsInvalid( |
| 23 | + array( |
| 24 | + array() // no configuration values |
| 25 | + ), |
| 26 | + 'required_value' |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * @test |
| 32 | + */ |
| 33 | + public function it_fails_when_a_configuration_is_valid_when_it_should_have_been_invalid() |
| 34 | + { |
| 35 | + $this->setExpectedException('\PHPUnit_Framework_ExpectationFailedException', 'invalid'); |
| 36 | + |
| 37 | + $this->assertConfigurationIsInvalid( |
| 38 | + array( |
| 39 | + array('required_value' => 'some value') |
| 40 | + ) |
| 41 | + ); |
| 42 | + } |
| 43 | + |
| 44 | + /** |
| 45 | + * @test |
| 46 | + */ |
| 47 | + public function it_can_assert_that_a_configuration_is_valid() |
| 48 | + { |
| 49 | + $this->assertConfigurationIsValid( |
| 50 | + array( |
| 51 | + array('required_value' => 'some value') |
| 52 | + ) |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + /** |
| 57 | + * @test |
| 58 | + */ |
| 59 | + public function it_fails_when_a_configuration_is_invalid_when_it_should_have_been_valid() |
| 60 | + { |
| 61 | + $this->setExpectedException('\PHPUnit_Framework_ExpectationFailedException', 'valid'); |
| 62 | + |
| 63 | + $this->assertConfigurationIsValid( |
| 64 | + array( |
| 65 | + array() |
| 66 | + ) |
| 67 | + ); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @test |
| 72 | + */ |
| 73 | + public function it_can_assert_that_a_processed_configuration_matches_the_expected_array_of_values() |
| 74 | + { |
| 75 | + $value = 'some value'; |
| 76 | + |
| 77 | + $this->assertProcessedConfigurationEquals( |
| 78 | + array( |
| 79 | + array(), |
| 80 | + array('required_value' => $value) |
| 81 | + ), |
| 82 | + array( |
| 83 | + 'required_value' => $value |
| 84 | + ) |
| 85 | + ); |
| 86 | + } |
| 87 | + |
| 88 | + /** |
| 89 | + * @test |
| 90 | + */ |
| 91 | + public function it_fails_when_a_processed_configuration_does_not_match_the_expected_array_of_values() |
| 92 | + { |
| 93 | + $value = 'some value'; |
| 94 | + |
| 95 | + $this->setExpectedException('\PHPUnit_Framework_ExpectationFailedException', 'equal'); |
| 96 | + $this->assertProcessedConfigurationEquals( |
| 97 | + array( |
| 98 | + array('required_value' => $value) |
| 99 | + ), |
| 100 | + array( |
| 101 | + 'invalid_key' => 'invalid_value' |
| 102 | + ) |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * @test |
| 108 | + */ |
| 109 | + public function it_throws_a_comparison_failed_exception_with_the_values_in_the_right_order() |
| 110 | + { |
| 111 | + $value = 'some value'; |
| 112 | + |
| 113 | + //$this->setExpectedException('\PHPUnit_Framework_ExpectationFailedException', 'equal'); |
| 114 | + $configurationValues = array( |
| 115 | + array('required_value' => $value) |
| 116 | + ); |
| 117 | + |
| 118 | + $expectedProcessedConfigurationValues = array( |
| 119 | + 'invalid_key' => 'invalid_value' |
| 120 | + ); |
| 121 | + |
| 122 | + try { |
| 123 | + $this->assertProcessedConfigurationEquals( |
| 124 | + $configurationValues, |
| 125 | + $expectedProcessedConfigurationValues |
| 126 | + ); |
| 127 | + } catch (\PHPUnit_Framework_ExpectationFailedException $exception) { |
| 128 | + $this->assertSame( |
| 129 | + $expectedProcessedConfigurationValues, |
| 130 | + $exception->getComparisonFailure()->getExpected() |
| 131 | + ); |
| 132 | + } |
| 133 | + } |
| 134 | +} |
0 commit comments