Page MenuHomePhorge

D5415.1775238193.diff
No OneTemporary

Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None

D5415.1775238193.diff

diff --git a/src/app/Console/ObjectReadCommand.php b/src/app/Console/ObjectReadCommand.php
--- a/src/app/Console/ObjectReadCommand.php
+++ b/src/app/Console/ObjectReadCommand.php
@@ -2,6 +2,8 @@
namespace App\Console;
+use App\Utils;
+
/**
* This abstract class provides a means to treat objects in our model using CRUD.
*/
@@ -20,6 +22,10 @@
$this->signature .= " {--attr=* : Attributes other than the primary unique key to include}";
+ if (Utils::isSoftDeletable($this->objectClass)) {
+ $this->signature .= " {--with-deleted : Consider deleted {$this->objectName}s}";
+ }
+
parent::__construct();
}
diff --git a/src/app/Console/ObjectUpdateCommand.php b/src/app/Console/ObjectUpdateCommand.php
--- a/src/app/Console/ObjectUpdateCommand.php
+++ b/src/app/Console/ObjectUpdateCommand.php
@@ -2,6 +2,8 @@
namespace App\Console;
+use App\Utils;
+
/**
* This abstract class provides a means to treat objects in our model using CRUD.
*/
@@ -34,7 +36,7 @@
$this->signature .= " {--{$property}=}";
}
- if (method_exists($class, 'restore')) {
+ if (Utils::isSoftDeletable($class)) {
$this->signature .= " {--with-deleted : Include deleted {$this->objectName}s}";
}
@@ -72,7 +74,7 @@
if ($class->timestamps && !in_array('updated_at', $list)) {
$list[] = 'updated_at';
}
- if (method_exists($class, 'restore') && !in_array('deleted_at', $list)) {
+ if (Utils::isSoftDeletable($class) && !in_array('deleted_at', $list)) {
$list[] = 'deleted_at';
}
}
diff --git a/src/tests/Feature/Console/Scalpel/Domain/ReadCommandTest.php b/src/tests/Feature/Console/Scalpel/Domain/ReadCommandTest.php
new file mode 100644
--- /dev/null
+++ b/src/tests/Feature/Console/Scalpel/Domain/ReadCommandTest.php
@@ -0,0 +1,67 @@
+<?php
+
+namespace Tests\Feature\Console\Scalpel\Domain;
+
+use App\Domain;
+use Tests\TestCase;
+
+class ReadCommandTest extends TestCase
+{
+ protected function setUp(): void
+ {
+ parent::setUp();
+
+ $this->deleteTestDomain('domain-delete.com');
+ }
+
+ protected function tearDown(): void
+ {
+ $this->deleteTestDomain('domain-delete.com');
+
+ parent::tearDown();
+ }
+
+ /**
+ * Test the command execution
+ */
+ public function testHandle(): void
+ {
+ // Test --help argument
+ $code = \Artisan::call("scalpel:domain:read --help");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertStringContainsString('--attr[=ATTR]', $output);
+ $this->assertStringContainsString('--with-deleted', $output);
+
+ // Test unknown domain
+ $code = \Artisan::call("scalpel:domain:read unknown-domain.tld --with-deleted");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame('No such domain unknown-domain.tld', $output);
+
+ // Test existing domain
+ $domain = $this->getTestDomain('domain-delete.com', ['type' => Domain::TYPE_EXTERNAL]);
+
+ $code = \Artisan::call("scalpel:domain:read {$domain->namespace} --attr=namespace");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("{$domain->id} {$domain->namespace}", $output);
+
+ // Test deleted domain
+ $domain->delete();
+ $code = \Artisan::call("scalpel:domain:read {$domain->namespace} --attr=namespace");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(1, $code);
+ $this->assertSame("No such domain {$domain->namespace}", $output);
+
+ $code = \Artisan::call("scalpel:domain:read {$domain->namespace} --attr=namespace --with-deleted");
+ $output = trim(\Artisan::output());
+
+ $this->assertSame(0, $code);
+ $this->assertSame("{$domain->id} {$domain->namespace}", $output);
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Fri, Apr 3, 5:43 PM (18 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823831
Default Alt Text
D5415.1775238193.diff (3 KB)

Event Timeline