From 5aca2f963ee646b0b13ffc303eadfd1a96db2d61 Mon Sep 17 00:00:00 2001 From: Zach Leigh Date: Fri, 25 Jan 2019 22:47:37 +0900 Subject: [PATCH] Add additional assertions to withSettings tests. --- src/Settings/HasSettings.php | 7 ++++--- tests/Unit/HasSettingsTest.php | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Settings/HasSettings.php b/src/Settings/HasSettings.php index a57c481..a642b21 100644 --- a/src/Settings/HasSettings.php +++ b/src/Settings/HasSettings.php @@ -164,10 +164,10 @@ 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 */ @@ -175,6 +175,7 @@ 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; } diff --git a/tests/Unit/HasSettingsTest.php b/tests/Unit/HasSettingsTest.php index 3abf299..3527904 100644 --- a/tests/Unit/HasSettingsTest.php +++ b/tests/Unit/HasSettingsTest.php @@ -147,9 +147,9 @@ 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')); } /** @@ -157,8 +157,8 @@ public function all_resources_with_setting_can_be_retrieved_from_hassettings() */ 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')); } }