Skip to content

Commit

Permalink
Add additional assertions to withSettings tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
zachleigh committed Jan 25, 2019
1 parent bfc7877 commit 5aca2f9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/Settings/HasSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,17 +164,18 @@ public function allowedSetting($key = null)
}

/**
* Get an array with all stored rows with a given setting and/or value.
* Get a collection with all users with the given setting and/or value.
*
* @param $key
* @param null $value
* @param string $key
* @param mixed $value
*
* @return \Illuminate\Support\Collection
*/
public static function withSetting($key, $value = null)
{
return static::all()->filter(function ($row) use ($key, $value) {
$setting = $row->settings($key);

if (!is_null($value)) {
return !is_null($setting) && $setting === $value;
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/HasSettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ public function all_allowed_values_can_be_retrieved_from_hassettings()
*/
public function all_resources_with_setting_can_be_retrieved_from_hassettings()
{
$collection = $this->user::withSetting('test_settings1');
$this->assertCount(1, $this->user::withSetting('test_settings1'));

$this->assertCount(1, $collection);
$this->assertCount(0, $this->user::withSetting('test_settings_invalid'));
}

/**
* @test
*/
public function all_resources_with_setting_and_value_can_be_retrieved_from_hassettings()
{
$collection = $this->user::withSetting('test_settings1', 'monkey');
$this->assertCount(1, $this->user::withSetting('test_settings1', 'monkey'));

$this->assertCount(1, $collection);
$this->assertCount(0, $this->user::withSetting('test_settings1', 'gorilla'));
}
}

0 comments on commit 5aca2f9

Please sign in to comment.