|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace EM\Tests\PHPUnit; |
| 4 | + |
| 5 | +use EM\CssCompiler\ScriptHandler; |
| 6 | +use EM\Tests\Environment\IntegrationTestSuite; |
| 7 | + |
| 8 | +/** |
| 9 | + * @see ScriptHandler |
| 10 | + */ |
| 11 | +class ScriptHandlerTest extends IntegrationTestSuite |
| 12 | +{ |
| 13 | + /*** *************************** CONFIGURATION VALIDATION *************************** ***/ |
| 14 | + /** |
| 15 | + * @see ScriptHandler::validateConfiguration |
| 16 | + * @test |
| 17 | + * |
| 18 | + * @expectedException \InvalidArgumentException |
| 19 | + */ |
| 20 | + function validateConfigurationExpectedExceptionOnNotExistingKey() |
| 21 | + { |
| 22 | + $this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [[]]); |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * @see ScriptHandler::validateConfiguration |
| 27 | + * @test |
| 28 | + * |
| 29 | + * @expectedException \InvalidArgumentException |
| 30 | + */ |
| 31 | + function validateConfigurationExpectedExceptionOnNotArray() |
| 32 | + { |
| 33 | + $this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [[ScriptHandler::CONFIG_MAIN_KEY]]); |
| 34 | + } |
| 35 | + |
| 36 | + /** |
| 37 | + * @see ScriptHandler::validateConfiguration |
| 38 | + * @test |
| 39 | + * |
| 40 | + * @expectedException \InvalidArgumentException |
| 41 | + */ |
| 42 | + function validateConfigurationExpectedExceptionOptionIsNotArray() |
| 43 | + { |
| 44 | + $arr = [ |
| 45 | + ScriptHandler::CONFIG_MAIN_KEY => [ |
| 46 | + 'string' |
| 47 | + ] |
| 48 | + ]; |
| 49 | + $this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [$arr]); |
| 50 | + } |
| 51 | + |
| 52 | + /** |
| 53 | + * @see ScriptHandler::validateConfiguration |
| 54 | + * @test |
| 55 | + */ |
| 56 | + function validateConfigurationOnValid() |
| 57 | + { |
| 58 | + $arr = [ |
| 59 | + ScriptHandler::CONFIG_MAIN_KEY => [ |
| 60 | + [ |
| 61 | + ScriptHandler::OPTION_KEY_INPUT => ['string'], |
| 62 | + ScriptHandler::OPTION_KEY_OUTPUT => 'string' |
| 63 | + ] |
| 64 | + ] |
| 65 | + ]; |
| 66 | + $result = $this->invokeMethod(new ScriptHandler(), 'validateConfiguration', [$arr]); |
| 67 | + $this->assertTrue($result); |
| 68 | + } |
| 69 | + |
| 70 | + /*** *************************** OPTIONS VALIDATION *************************** ***/ |
| 71 | + /** |
| 72 | + * @see ScriptHandler::validateOptions |
| 73 | + * @test |
| 74 | + * |
| 75 | + * @expectedException \InvalidArgumentException |
| 76 | + */ |
| 77 | + function validateOptionsExpectedExceptionOnMissingInput() |
| 78 | + { |
| 79 | + $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[ScriptHandler::OPTION_KEY_OUTPUT]]); |
| 80 | + } |
| 81 | + |
| 82 | + /** |
| 83 | + * @see ScriptHandler::validateOptions |
| 84 | + * @test |
| 85 | + * |
| 86 | + * @expectedException \InvalidArgumentException |
| 87 | + */ |
| 88 | + function validateOptionsExpectedExceptionOnMissingOutput() |
| 89 | + { |
| 90 | + $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[ScriptHandler::OPTION_KEY_INPUT]]); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @see ScriptHandler::validateOptions |
| 95 | + * @test |
| 96 | + * |
| 97 | + * @expectedException \InvalidArgumentException |
| 98 | + */ |
| 99 | + function validateOptionsExpectedExceptionOnInputNotArray() |
| 100 | + { |
| 101 | + $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[ |
| 102 | + ScriptHandler::OPTION_KEY_INPUT => 'string', |
| 103 | + ScriptHandler::OPTION_KEY_OUTPUT => 'string' |
| 104 | + ]]); |
| 105 | + } |
| 106 | + |
| 107 | + /** |
| 108 | + * @see ScriptHandler::validateOptions |
| 109 | + * @test |
| 110 | + * |
| 111 | + * @expectedException \InvalidArgumentException |
| 112 | + */ |
| 113 | + function validateOptionsExpectedExceptionOnOutputNotString() |
| 114 | + { |
| 115 | + $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[ |
| 116 | + ScriptHandler::OPTION_KEY_INPUT => ['string'], |
| 117 | + ScriptHandler::OPTION_KEY_OUTPUT => ['string'] |
| 118 | + ]]); |
| 119 | + } |
| 120 | + |
| 121 | + /** |
| 122 | + * @see ScriptHandler::validateOptions |
| 123 | + * @test |
| 124 | + */ |
| 125 | + function validateOptionsOnValid() |
| 126 | + { |
| 127 | + $result = $this->invokeMethod(new ScriptHandler(), 'validateOptions', [[ |
| 128 | + ScriptHandler::OPTION_KEY_INPUT => ['string'], |
| 129 | + ScriptHandler::OPTION_KEY_OUTPUT => 'string' |
| 130 | + ]]); |
| 131 | + |
| 132 | + $this->assertTrue($result); |
| 133 | + } |
| 134 | +} |
0 commit comments