From aac4e4ed6ba5a2522ac0b1de37bd68682fbdf94b Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Fri, 31 Mar 2017 09:26:27 +0200 Subject: [PATCH 1/3] fix Scrutinizer bugs --- src/Notifynder/Traits/Notifable.php | 22 ++++++++++++++++++++ src/Notifynder/Traits/NotifableLaravel53.php | 22 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/src/Notifynder/Traits/Notifable.php b/src/Notifynder/Traits/Notifable.php index b2c6e5c..96e1c70 100644 --- a/src/Notifynder/Traits/Notifable.php +++ b/src/Notifynder/Traits/Notifable.php @@ -11,6 +11,28 @@ trait Notifable { use NotifableBasic; + /** + * Define a polymorphic one-to-many relationship. + * + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\MorphMany + */ + abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null); + + /** + * Define a one-to-many relationship. + * + * @param string $related + * @param string $foreignKey + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + abstract public function hasMany($related, $foreignKey = null, $localKey = null); + /** * Get the notifications Relationship. * diff --git a/src/Notifynder/Traits/NotifableLaravel53.php b/src/Notifynder/Traits/NotifableLaravel53.php index abd016f..392e4d8 100644 --- a/src/Notifynder/Traits/NotifableLaravel53.php +++ b/src/Notifynder/Traits/NotifableLaravel53.php @@ -11,6 +11,28 @@ trait NotifableLaravel53 { use NotifableBasic; + /** + * Define a polymorphic one-to-many relationship. + * + * @param string $related + * @param string $name + * @param string $type + * @param string $id + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\MorphMany + */ + abstract public function morphMany($related, $name, $type = null, $id = null, $localKey = null); + + /** + * Define a one-to-many relationship. + * + * @param string $related + * @param string $foreignKey + * @param string $localKey + * @return \Illuminate\Database\Eloquent\Relations\HasMany + */ + abstract public function hasMany($related, $foreignKey = null, $localKey = null); + /** * Get the notifications Relationship. * From 31b05c80bb9bb66963df9a44299156fa76cdc8a3 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 30 May 2017 11:19:25 +0200 Subject: [PATCH 2/3] #277 - fix `mergeFillables()` and add additional unittests --- src/Notifynder/Models/Notification.php | 2 +- tests/integration/Collections/ConfigTest.php | 26 ++++++ tests/integration/Models/NotificationTest.php | 88 +++++++++++++++++++ 3 files changed, 115 insertions(+), 1 deletion(-) create mode 100644 tests/integration/Models/NotificationTest.php diff --git a/src/Notifynder/Models/Notification.php b/src/Notifynder/Models/Notification.php index b08e72c..0d5ce4d 100644 --- a/src/Notifynder/Models/Notification.php +++ b/src/Notifynder/Models/Notification.php @@ -119,7 +119,7 @@ public function getCustomFillableFields() */ protected function mergeFillables() { - $fillables = array_unique($this->getFillable() + $this->getCustomFillableFields()); + $fillables = array_unique(array_merge($this->getFillable(), $this->getCustomFillableFields())); return $fillables; } diff --git a/tests/integration/Collections/ConfigTest.php b/tests/integration/Collections/ConfigTest.php index 99f415b..a7129d8 100644 --- a/tests/integration/Collections/ConfigTest.php +++ b/tests/integration/Collections/ConfigTest.php @@ -39,6 +39,32 @@ public function testGetNotifiedModelFail() } public function testGetAdditionalFields() + { + $config = app('notifynder.config'); + $config->set('additional_fields.fillable', ['fillable_field']); + $config->set('additional_fields.required', ['required_field']); + $this->assertInternalType('array', $config->getAdditionalFields()); + $this->assertCount(2, $config->getAdditionalFields()); + $this->assertSame(['required_field', 'fillable_field'], $config->getAdditionalFields()); + } + + public function testGetAdditionalFieldsFillable() + { + $config = app('notifynder.config'); + $config->set('additional_fields.fillable', ['fillable_field']); + $this->assertInternalType('array', $config->getAdditionalFields()); + $this->assertSame(['fillable_field'], $config->getAdditionalFields()); + } + + public function testGetAdditionalFieldsRequired() + { + $config = app('notifynder.config'); + $config->set('additional_fields.required', ['required_field']); + $this->assertInternalType('array', $config->getAdditionalFields()); + $this->assertSame(['required_field'], $config->getAdditionalFields()); + } + + public function testGetAdditionalFieldsEmpty() { $config = app('notifynder.config'); $this->assertInternalType('array', $config->getAdditionalFields()); diff --git a/tests/integration/Models/NotificationTest.php b/tests/integration/Models/NotificationTest.php new file mode 100644 index 0000000..21a0a08 --- /dev/null +++ b/tests/integration/Models/NotificationTest.php @@ -0,0 +1,88 @@ +assertInternalType('array', $notification->getFillable()); + $this->assertSame([ + 'to_id', + 'to_type', + 'from_id', + 'from_type', + 'category_id', + 'read', + 'url', + 'extra', + 'expires_at', + 'stack_id', + ], $notification->getFillable()); + } + + public function testFillablesCustomFillables() + { + $config = app('notifynder.config'); + $config->set('additional_fields.fillable', ['fillable_field']); + $notification = new Notification(); + $this->assertInternalType('array', $notification->getFillable()); + $this->assertSame([ + 'to_id', + 'to_type', + 'from_id', + 'from_type', + 'category_id', + 'read', + 'url', + 'extra', + 'expires_at', + 'stack_id', + 'fillable_field', + ], $notification->getFillable()); + } + + public function testFillablesCustomRequired() + { + $config = app('notifynder.config'); + $config->set('additional_fields.required', ['required_field']); + $notification = new Notification(); + $this->assertInternalType('array', $notification->getFillable()); + $this->assertSame([ + 'to_id', + 'to_type', + 'from_id', + 'from_type', + 'category_id', + 'read', + 'url', + 'extra', + 'expires_at', + 'stack_id', + 'required_field', + ], $notification->getFillable()); + } + + public function testFillablesCustom() + { + $config = app('notifynder.config'); + $config->set('additional_fields.fillable', ['fillable_field']); + $config->set('additional_fields.required', ['required_field']); + $notification = new Notification(); + $this->assertInternalType('array', $notification->getFillable()); + $this->assertSame([ + 'to_id', + 'to_type', + 'from_id', + 'from_type', + 'category_id', + 'read', + 'url', + 'extra', + 'expires_at', + 'stack_id', + 'required_field', + 'fillable_field', + ], $notification->getFillable()); + } +} From f192e26a6fe92130f0f2a93d43ace09e303b2129 Mon Sep 17 00:00:00 2001 From: Tom Witkowski Date: Tue, 30 May 2017 09:19:37 +0000 Subject: [PATCH 3/3] Apply fixes from StyleCI [ci skip] [skip ci] --- tests/integration/Models/NotificationTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/integration/Models/NotificationTest.php b/tests/integration/Models/NotificationTest.php index 21a0a08..1a02eb8 100644 --- a/tests/integration/Models/NotificationTest.php +++ b/tests/integration/Models/NotificationTest.php @@ -1,4 +1,5 @@