From 5f007399781464ddb42c2c92bb0d90a3b10377d6 Mon Sep 17 00:00:00 2001 From: Etxben Date: Fri, 18 Nov 2022 13:40:59 +0100 Subject: [PATCH 1/3] Add new koan --- koans/EmptyIsNullOrIssetKoan.php | 67 ++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 koans/EmptyIsNullOrIssetKoan.php diff --git a/koans/EmptyIsNullOrIssetKoan.php b/koans/EmptyIsNullOrIssetKoan.php new file mode 100644 index 0000000..c499e04 --- /dev/null +++ b/koans/EmptyIsNullOrIssetKoan.php @@ -0,0 +1,67 @@ +assertEquals(true, is_null(NULL)); + $this->assertEquals(false, is_null("")); + } + + /** + * @test + */ + function testWorkingWithIsset() + { + //isset return true if variable exist and it is not null + $this->assertEquals(false, isset($something)); + + $array = array('bar' => 1, 'foo' => null); + $this->assertEquals(true, isset($array)); + $this->assertEquals(true , isset($array['bar'])); + $this->assertEquals(false , isset($array['foo'])); + $this->assertEquals(false , isset($array['barfoo'])); + + } + + /** + * @test + */ + function testWorkingWithEmpty() + { + //Working with numbers + $this->assertEquals(true, empty(0)); + $this->assertEquals(false, empty(1)); + + //Working with decimals + $this->assertEquals(true, empty(0.0)); + $this->assertEquals(false, empty(0.1)); + + //Working wiht strings + $this->assertEquals(true, empty("")); + $this->assertEquals(false, empty(" ")); + + //Working with booleans + $this->assertEquals(true, empty(false)); + $this->assertEquals(false, empty(true)); + + //working with arrays + $this->assertEquals(true, empty(array())); + $this->assertEquals(false, empty(array(1))); + + //working with objects + $this->assertEquals(false, empty((object)array())); + $this->assertEquals(true, empty(null)); + $this->assertEquals(true, empty($something)); + } +} + +?> From 3270713ff45d6c6dbe2b0b0d9c9445797a34c088 Mon Sep 17 00:00:00 2001 From: Etxben Date: Thu, 24 Nov 2022 10:38:24 +0100 Subject: [PATCH 2/3] Modify assserts to fail --- koans/EmptyIsNullOrIssetKoan.php | 51 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/koans/EmptyIsNullOrIssetKoan.php b/koans/EmptyIsNullOrIssetKoan.php index c499e04..4f199e4 100644 --- a/koans/EmptyIsNullOrIssetKoan.php +++ b/koans/EmptyIsNullOrIssetKoan.php @@ -9,59 +9,58 @@ class EmptyIsNullOrIssetKoan extends TestCase /** * @test */ - function testWorkingWithIsNull() + function testMethodIsNull() { - //is_null return true if variable is null - $this->assertEquals(true, is_null(NULL)); - $this->assertEquals(false, is_null("")); + //is_null return __ if variable is null + $this->assertEquals(__, is_null(NULL)); + $this->assertEquals(__, is_null("")); } /** * @test */ - function testWorkingWithIsset() + function testMethodIsset() { - //isset return true if variable exist and it is not null - $this->assertEquals(false, isset($something)); + //isset return __ if variable exist and it is not null + $this->assertEquals(__, isset($something)); $array = array('bar' => 1, 'foo' => null); - $this->assertEquals(true, isset($array)); - $this->assertEquals(true , isset($array['bar'])); - $this->assertEquals(false , isset($array['foo'])); - $this->assertEquals(false , isset($array['barfoo'])); + $this->assertEquals(__, isset($array)); + $this->assertEquals(__ , isset($array['bar'])); + $this->assertEquals(__ , isset($array['foo'])); + $this->assertEquals(__ , isset($array['barfoo'])); } /** * @test */ - function testWorkingWithEmpty() + function testMethodEmpty() { //Working with numbers - $this->assertEquals(true, empty(0)); - $this->assertEquals(false, empty(1)); + $this->assertEquals(__, empty(0)); + $this->assertEquals(__, empty(1)); //Working with decimals - $this->assertEquals(true, empty(0.0)); - $this->assertEquals(false, empty(0.1)); + $this->assertEquals(__, empty(0.0)); + $this->assertEquals(__, empty(0.1)); //Working wiht strings - $this->assertEquals(true, empty("")); - $this->assertEquals(false, empty(" ")); + $this->assertEquals(__, empty("")); + $this->assertEquals(__, empty(" ")); //Working with booleans - $this->assertEquals(true, empty(false)); - $this->assertEquals(false, empty(true)); + $this->assertEquals(__, empty(false)); + $this->assertEquals(__, empty(true)); //working with arrays - $this->assertEquals(true, empty(array())); - $this->assertEquals(false, empty(array(1))); + $this->assertEquals(__, empty(array())); + $this->assertEquals(__, empty(array(1))); //working with objects - $this->assertEquals(false, empty((object)array())); - $this->assertEquals(true, empty(null)); - $this->assertEquals(true, empty($something)); + $this->assertEquals(__, empty((object)array())); + $this->assertEquals(__, empty(null)); + $this->assertEquals(__, empty($something)); } } - ?> From 4c85da3b8154a5bde978bd4db28fe107f428ad85 Mon Sep 17 00:00:00 2001 From: Etxben Date: Thu, 24 Nov 2022 10:52:40 +0100 Subject: [PATCH 3/3] Modify comments --- koans/EmptyIsNullOrIssetKoan.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/koans/EmptyIsNullOrIssetKoan.php b/koans/EmptyIsNullOrIssetKoan.php index 4f199e4..dd4d4ea 100644 --- a/koans/EmptyIsNullOrIssetKoan.php +++ b/koans/EmptyIsNullOrIssetKoan.php @@ -11,7 +11,7 @@ class EmptyIsNullOrIssetKoan extends TestCase */ function testMethodIsNull() { - //is_null return __ if variable is null + //is_null return true if variable is null $this->assertEquals(__, is_null(NULL)); $this->assertEquals(__, is_null("")); } @@ -21,7 +21,7 @@ function testMethodIsNull() */ function testMethodIsset() { - //isset return __ if variable exist and it is not null + //isset return true if variable exist and it is not null $this->assertEquals(__, isset($something)); $array = array('bar' => 1, 'foo' => null); @@ -37,27 +37,27 @@ function testMethodIsset() */ function testMethodEmpty() { - //Working with numbers + //Working with numbers. Returns true if is 0 $this->assertEquals(__, empty(0)); $this->assertEquals(__, empty(1)); - //Working with decimals + //Working with decimals. Returns true if is 0.0 $this->assertEquals(__, empty(0.0)); $this->assertEquals(__, empty(0.1)); - //Working wiht strings + //Working wiht strings. Return false if has any character. $this->assertEquals(__, empty("")); $this->assertEquals(__, empty(" ")); - //Working with booleans + //Working with booleans. Return false if is true $this->assertEquals(__, empty(false)); $this->assertEquals(__, empty(true)); - //working with arrays + //working with arrays. Return true if the array has any value. $this->assertEquals(__, empty(array())); $this->assertEquals(__, empty(array(1))); - //working with objects + //working with objects. Return true if value is an instance $this->assertEquals(__, empty((object)array())); $this->assertEquals(__, empty(null)); $this->assertEquals(__, empty($something));