Created
July 17, 2015 07:57
-
-
Save teklakct/35621464f4f1ab285d3b to your computer and use it in GitHub Desktop.
Strings comparision and check variable is set
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| StringsCompare | |
| 52 - it compare strings using strcasecmp | |
| expected false, but got true. | |
| 1 specs | |
| 4 examples (3 passed, 1 failed) | |
| 20ms |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| class StringsCompare | |
| { | |
| public function compareStringsStrtoupper($method, $options) | |
| { | |
| if (strtoupper($method) == 'POST' | |
| && !isset($options['body']) | |
| && !isset($options['json']) | |
| ) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| public function compareStringsStrcasecmp($method, $options) | |
| { | |
| if (!strcasecmp($method, 'post') && !isset($options['body'], $options['json'])) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| public function compareStringsStrcasecmpAlternative($method, $options) | |
| { | |
| if (!strcasecmp($method, 'post') && !isset($options['body']) && !isset($options['json'])) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| public function oldCompare($method, $options) | |
| { | |
| if ($method == 'POST' | |
| && !isset($options['body']) | |
| && !isset($options['json']) | |
| ) { | |
| return true; | |
| } | |
| return false; | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace spec; | |
| use PhpSpec\ObjectBehavior; | |
| use Prophecy\Argument; | |
| /** | |
| * Class StringsCompareSpec | |
| * @package spec | |
| * @mixin \StringsCompare | |
| */ | |
| class StringsCompareSpec extends ObjectBehavior | |
| { | |
| function it_is_initializable() | |
| { | |
| $this->shouldHaveType('StringsCompare'); | |
| } | |
| function it_compare_strings_using_strtoupper() { | |
| $method = 'post'; | |
| $options = []; | |
| $this->compareStringsStrtoupper($method, $options)->shouldBe(true); | |
| $method = 'POST'; | |
| $options = []; | |
| $this->compareStringsStrtoupper($method, $options)->shouldBe(true); | |
| $method = 'PoST'; | |
| $options = []; | |
| $this->compareStringsStrtoupper($method, $options)->shouldBe(true); | |
| $method = 'POST'; | |
| $options = [ | |
| 'body' => '' | |
| ]; | |
| $this->compareStringsStrtoupper($method, $options)->shouldBe(false); | |
| $method = 'POST'; | |
| $options = [ | |
| 'body' => '', | |
| 'json' => '' | |
| ]; | |
| $this->compareStringsStrtoupper($method, $options)->shouldBe(false); | |
| } | |
| function it_compare_strings_using_strcasecmp() { | |
| $method = 'post'; | |
| $options = []; | |
| $this->compareStringsStrcasecmp($method, $options)->shouldBe(true); | |
| $method = 'POST'; | |
| $options = []; | |
| $this->compareStringsStrcasecmp($method, $options)->shouldBe(true); | |
| $method = 'PoST'; | |
| $options = []; | |
| $this->compareStringsStrcasecmp($method, $options)->shouldBe(true); | |
| $method = 'POST'; | |
| $options = [ | |
| 'json' => '' | |
| ]; | |
| /** | |
| * These won't work | |
| */ | |
| $this->compareStringsStrcasecmp($method, $options)->shouldBe(false); | |
| $method = 'POST'; | |
| $options = [ | |
| 'body' => '', | |
| 'json' => '' | |
| ]; | |
| $this->compareStringsStrcasecmp($method, $options)->shouldBe(false); | |
| } | |
| function it_compare_strings_using_strcasecmp_alternative() { | |
| $method = 'post'; | |
| $options = []; | |
| $this->compareStringsStrcasecmpAlternative($method, $options)->shouldBe(true); | |
| $method = 'POST'; | |
| $options = []; | |
| $this->compareStringsStrcasecmpAlternative($method, $options)->shouldBe(true); | |
| $method = 'PoST'; | |
| $options = []; | |
| $this->compareStringsStrcasecmpAlternative($method, $options)->shouldBe(true); | |
| $method = 'POST'; | |
| $options = [ | |
| 'json' => '' | |
| ]; | |
| $this->compareStringsStrcasecmpAlternative($method, $options)->shouldBe(false); | |
| $method = 'POST'; | |
| $options = [ | |
| 'body' => '', | |
| 'json' => '' | |
| ]; | |
| $this->compareStringsStrcasecmpAlternative($method, $options)->shouldBe(false); | |
| } | |
| function if_compare_string() | |
| { | |
| $method = 'POST'; | |
| $options = [ | |
| 'body' => '' | |
| ]; | |
| $this->oldCompare($method, $options)->shouldBe(false); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment