Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
dist: trusty
language: php

php:
- 7.1
- 7.2

install:
- composer install --prefer-dist
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about moving this to composer.json via

$ composer config preferred-install dist

?

Copy link
Copy Markdown
Author

@peter279k peter279k Aug 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@localheinz, thank you for your reply.
It looks like adding this --prefer-dist config in composer.json instead of letting this be the option in composer install command.

I think revert this option in composer install command is the proper way if this option is required.

What do you think? Thanks.

- composer install

script:
- vendor/bin/phpunit
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"php": "^7.1"
},
"require-dev": {
"phpunit/phpunit": "~7.0"
"phpunit/phpunit": "^7.0"
},
"autoload": {
"files": ["src/bootstrap.php"]
Expand Down
7 changes: 5 additions & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@

<filter>
<whitelist>
<directory suffix=".php">./lib/</directory>
<directory suffix=".php">src</directory>
<exclude>
<file suffix=".php">src/bootstrap.php</file>
</exclude>
</whitelist>
</filter>
</phpunit>
</phpunit>
4 changes: 3 additions & 1 deletion src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@

require __DIR__ . '/iter.fn.php';
require __DIR__ . '/iter.php';
require __DIR__ . '/iter.rewindable.php';
require __DIR__ . '/iter.rewindable.php';
require __DIR__ . '/../test/MyIterator.php';
require __DIR__ . '/../test/MyIteratorAgg.php';
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files shouldn't be included here, as they are only needed for tests. Either we should have a separate bootstrap file in the test directory, or we can explicitly include the files in the test, or we can place the class definitions in the test file (like _CountableTestDummy).

Copy link
Copy Markdown
Author

@peter279k peter279k Feb 28, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I will move the related test class bootstrap.php file to the test folder.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the autoload-dev in composer.json to autoload the required *Test.php files.

36 changes: 36 additions & 0 deletions test/MyIterator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace iter;

class MyIterator implements \Iterator {
private $position = 0;
private $array = [
"firstelement",
"secondelement",
"lastelement",
];

public function __construct() {
$this->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]);
}
}
17 changes: 17 additions & 0 deletions test/MyIteratorAgg.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace iter;

class MyIteratorAgg implements \IteratorAggregate {
public $property1 = "Public property one";
public $property2 = "Public property two";
public $property3 = "Public property three";

public function __construct() {
$this->property4 = "last property";
}

public function getIterator() {
return new \ArrayIterator($this);
}
}
8 changes: 8 additions & 0 deletions test/iterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,10 @@ public function testCount() {
$this->assertSame(42, count(new _CountableTestDummy));
}

public function testCountWithStringCount() {
$this->assertSame(3, count(new MyIterator()));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the purpose of this test. This is testing counting of an iterator, which is also tested by the $this->assertSame(5, count(toIter([1, 2, 3, 4, 5]))) line above. I'm also not clear on why this is called "testCountWithStringCount". How is this related to strings?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it's my fault to create the duplicated tests.
I will remove this test method.

}

public function testIsEmpty() {
$this->assertTrue(isEmpty([]));
$this->assertFalse(isEmpty([null]));
Expand All @@ -368,6 +372,10 @@ public function testIsEmpty() {
$this->assertFalse(isEmpty(repeat(42)));
}

public function testIsEmptyWithValidIteratorAgg() {
$this->assertFalse(isEmpty(new MyIteratorAgg()));
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess we should test count() with an iterator aggregate as well, looks like that case isn't present yet.

}

public function testToArray() {
$this->assertSame([1, 2, 3], toArray(['a' => 1, 'b' => 2, 'c' => 3]));
$this->assertSame(
Expand Down