Skip to content

Commit

Permalink
Implements unique in findAll
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolashohm committed Feb 18, 2015
1 parent 2b52c8b commit bd2f70f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Storage/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ public function __construct($path)

public function findAll()
{
return array_filter(explode(PHP_EOL, file_get_contents($this->path)));
$all = explode(PHP_EOL, file_get_contents($this->path));
$all = array_filter($all);
$all = array_unique($all);
return $all;
}

public function add($user)
Expand Down
6 changes: 6 additions & 0 deletions test/Networker/Storage/FileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ public function testAllExisting()
$this->sut->addAll($this->userList);
$this->assertEquals($this->userListRaw, file_get_contents($this->file));
}

public function testFindAllNoDuplicates()
{
file_put_contents($this->file, $this->userListRaw . 'octocat' . PHP_EOL);
$this->assertEquals($this->userList, $this->sut->findAll());
}
}

0 comments on commit bd2f70f

Please sign in to comment.