Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/polls.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorTortue Torche <tortuetorche@users.noreply.github.com>2019-12-10 15:43:47 +0300
committerTortue Torche <tortuetorche@users.noreply.github.com>2019-12-10 17:03:55 +0300
commit30876940adf9cf65f2f1846ba08fa6253dece933 (patch)
treec0ad92a0a92d125de07b91618d6b83da3f41a015 /tests
parentc780daf33d3e2574bb9578f87be262c285662337 (diff)
Patch FactoryMuffin::generate() method to support dynamic setter and getter
with the OCP\AppFramework\Db\Entity class Signed-off-by: Tortue Torche <tortuetorche@users.noreply.github.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/FactoryMuffin.php36
-rw-r--r--tests/Unit/UnitTestCase.php5
2 files changed, 38 insertions, 3 deletions
diff --git a/tests/Unit/FactoryMuffin.php b/tests/Unit/FactoryMuffin.php
new file mode 100644
index 00000000..a8fb7d59
--- /dev/null
+++ b/tests/Unit/FactoryMuffin.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace OCA\Polls\Tests\Unit;
+
+use League\FactoryMuffin\FactoryMuffin as OriginalFactoryMuffin;
+use OCP\AppFramework\Db\Entity;
+
+class FactoryMuffin extends OriginalFactoryMuffin
+{
+ /**
+ * Generate and set the model attributes.
+ * NOTE: Patch the original method to support dynamic setter and getter
+ * of the OCP\AppFramework\Db\Entity class
+ *
+ * @param object $model The model instance.
+ * @param array $attr The model attributes.
+ *
+ * @return void
+ */
+ protected function generate($model, array $attr = [])
+ {
+ foreach ($attr as $key => $kind) {
+ $value = $this->factory->generate($kind, $model, $this);
+
+ $setter = 'set'.ucfirst(static::camelize($key));
+ // check if there is a setter and use it instead
+ if ($model instanceof Entity && is_callable([$model, $setter])) {
+ $model->$setter($value);
+ } elseif (method_exists($model, $setter) && is_callable([$model, $setter])) {
+ $model->$setter($value);
+ } else {
+ $model->$key = $value;
+ }
+ }
+ }
+}
diff --git a/tests/Unit/UnitTestCase.php b/tests/Unit/UnitTestCase.php
index 6be39d40..2edf4af1 100644
--- a/tests/Unit/UnitTestCase.php
+++ b/tests/Unit/UnitTestCase.php
@@ -23,10 +23,9 @@
namespace OCA\Polls\Tests\Unit;
-use League\FactoryMuffin\FactoryMuffin;
-use PHPUnit\Framework\TestCase as PHPUnit_Framework_TestCase;
+use PHPUnit\Framework\TestCase;
-abstract class UnitTestCase extends PHPUnit_Framework_TestCase {
+abstract class UnitTestCase extends TestCase {
/** @var FactoryMuffin */
protected $fm;