From 3e76fbcd73fb8dd1e776aff59de02ab198556d34 Mon Sep 17 00:00:00 2001 From: peter279k Date: Tue, 6 Feb 2018 01:07:15 +0800 Subject: [PATCH 1/2] test enhancement --- .travis.yml | 3 +-- composer.json | 2 +- phpunit.xml.dist | 7 +++++-- src/bootstrap.php | 4 +++- test/MyIterator.php | 36 ++++++++++++++++++++++++++++++++++++ test/MyIteratorAgg.php | 17 +++++++++++++++++ test/iterTest.php | 8 ++++++++ 7 files changed, 71 insertions(+), 6 deletions(-) create mode 100644 test/MyIterator.php create mode 100644 test/MyIteratorAgg.php diff --git a/.travis.yml b/.travis.yml index cbe9517..de526eb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,3 @@ -dist: trusty language: php php: @@ -6,7 +5,7 @@ php: - 7.2 install: - - composer install --prefer-dist + - composer install script: - vendor/bin/phpunit diff --git a/composer.json b/composer.json index 288922e..aeef0f9 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "php": "^7.1" }, "require-dev": { - "phpunit/phpunit": "~7.0" + "phpunit/phpunit": "^7.0" }, "autoload": { "files": ["src/bootstrap.php"] diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 0e317e9..5dc58a5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -18,7 +18,10 @@ - ./lib/ + src + + src/bootstrap.php + - \ No newline at end of file + diff --git a/src/bootstrap.php b/src/bootstrap.php index 2bdb16f..cceb9ba 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -2,4 +2,6 @@ require __DIR__ . '/iter.fn.php'; require __DIR__ . '/iter.php'; -require __DIR__ . '/iter.rewindable.php'; \ No newline at end of file +require __DIR__ . '/iter.rewindable.php'; +require __DIR__ . '/../test/MyIterator.php'; +require __DIR__ . '/../test/MyIteratorAgg.php'; diff --git a/test/MyIterator.php b/test/MyIterator.php new file mode 100644 index 0000000..a2ca360 --- /dev/null +++ b/test/MyIterator.php @@ -0,0 +1,36 @@ +position = 0; + } + + public function rewind() { + $this->position = 0; + } + + public function current() { + return $this->array[$this->position]; + } + + public function key() { + return $this->position; + } + + public function next() { + ++$this->position; + } + + public function valid() { + return isset($this->array[$this->position]); + } +} diff --git a/test/MyIteratorAgg.php b/test/MyIteratorAgg.php new file mode 100644 index 0000000..5bee9e8 --- /dev/null +++ b/test/MyIteratorAgg.php @@ -0,0 +1,17 @@ +property4 = "last property"; + } + + public function getIterator() { + return new \ArrayIterator($this); + } +} diff --git a/test/iterTest.php b/test/iterTest.php index e8311dc..407c5a3 100644 --- a/test/iterTest.php +++ b/test/iterTest.php @@ -359,6 +359,10 @@ public function testCount() { $this->assertSame(42, count(new _CountableTestDummy)); } + public function testCountWithStringCount() { + $this->assertSame(3, count(new MyIterator())); + } + public function testIsEmpty() { $this->assertTrue(isEmpty([])); $this->assertFalse(isEmpty([null])); @@ -368,6 +372,10 @@ public function testIsEmpty() { $this->assertFalse(isEmpty(repeat(42))); } + public function testIsEmptyWithValidIteratorAgg() { + $this->assertFalse(isEmpty(new MyIteratorAgg())); + } + public function testToArray() { $this->assertSame([1, 2, 3], toArray(['a' => 1, 'b' => 2, 'c' => 3])); $this->assertSame( From 666e54e51ddbe6f15467d32b0b6e6dfad807de83 Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 1 Mar 2018 00:37:23 +0800 Subject: [PATCH 2/2] do the request changes --- composer.json | 5 +++++ phpunit.xml.dist | 2 +- src/bootstrap.php | 2 -- test/iterTest.php | 9 +++------ 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index aeef0f9..892d93e 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,11 @@ "autoload": { "files": ["src/bootstrap.php"] }, + "autoload-dev": { + "psr-4": { + "iter\\": "test" + } + }, "extra": { "branch-alias": { "dev-master": "2.0-dev" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5dc58a5..cc14a19 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,7 +9,7 @@ processIsolation="false" stopOnFailure="false" syntaxCheck="false" - bootstrap="./src/bootstrap.php"> + bootstrap="./vendor/autoload.php"> ./test/ diff --git a/src/bootstrap.php b/src/bootstrap.php index cceb9ba..61b3f2a 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -3,5 +3,3 @@ require __DIR__ . '/iter.fn.php'; require __DIR__ . '/iter.php'; require __DIR__ . '/iter.rewindable.php'; -require __DIR__ . '/../test/MyIterator.php'; -require __DIR__ . '/../test/MyIteratorAgg.php'; diff --git a/test/iterTest.php b/test/iterTest.php index 407c5a3..dd0ec48 100644 --- a/test/iterTest.php +++ b/test/iterTest.php @@ -359,10 +359,6 @@ public function testCount() { $this->assertSame(42, count(new _CountableTestDummy)); } - public function testCountWithStringCount() { - $this->assertSame(3, count(new MyIterator())); - } - public function testIsEmpty() { $this->assertTrue(isEmpty([])); $this->assertFalse(isEmpty([null])); @@ -370,10 +366,11 @@ public function testIsEmpty() { $this->assertFalse(isEmpty(toArray([null]))); $this->assertTrue(isEmpty(repeat(42, 0))); $this->assertFalse(isEmpty(repeat(42))); + $this->assertFalse(isEmpty(new MyIteratorAgg())); } - public function testIsEmptyWithValidIteratorAgg() { - $this->assertFalse(isEmpty(new MyIteratorAgg())); + public function testCountWithValidIteratorAgg() { + $this->assertSame(4, count(new MyIteratorAgg())); } public function testToArray() {