Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F5425372
D240.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D240.diff
View Options
diff --git a/tests/Console/Commands/InspireTest.php b/tests/Console/Commands/InspireTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Console/Commands/InspireTest.php
@@ -0,0 +1,18 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Console\Commands;
+
+class InspireTest extends TestCase {
+
+ /**
+ * @var string
+ */
+ protected $class = 'Nasqueron\Notifications\Console\Commands\Inspire';
+
+ public function testExecute () {
+ // A quote contain a - character and is embedded by PHP_EOL
+ $this->tester->execute(['command' => $this->command->getName()]);
+ $this->assertRegexp('/\n.*-.*\n/', $this->tester->getDisplay());
+ }
+
+}
diff --git a/tests/Console/Commands/TestCase.php b/tests/Console/Commands/TestCase.php
new file mode 100644
--- /dev/null
+++ b/tests/Console/Commands/TestCase.php
@@ -0,0 +1,59 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Console\Commands;
+
+use Symfony\Component\Console\Tester\CommandTester;
+
+use Nasqueron\Notifications\Tests\TestCase as BaseTestCase;
+
+use Artisan;
+
+class TestCase extends BaseTestCase {
+
+ ///
+ /// Commands test environment
+ ///
+
+ /**
+ * @var Symfony\Component\Console\Command
+ */
+ protected $command;
+
+ /**
+ * @var Symfony\Component\Console\Tester\CommandTester;
+ */
+ protected $tester;
+
+ public function setUp () {
+ parent::setUp();
+
+ $this->command = $this->findCommand($this->class);
+ $this->tester = new CommandTester($this->command);
+ }
+
+ ///
+ /// Helper methods to manipulate command arrays
+ ///
+
+ /**
+ * Finds the first instance of the expected type in the specified array.
+ *
+ * @param mixed $expectedType The type to find among the array elements
+ * @param array $haystack The array where to find
+ * @return mixed|null If not found, null. Otherwise, the found item.
+ */
+ protected static function findInstanceOf ($expectedType, $haystack) {
+ foreach ($haystack as $item) {
+ if ($item instanceof $expectedType) {
+ return $item;
+ }
+ }
+
+ return null;
+ }
+
+ protected function findCommand ($expectedType) {
+ return self::findInstanceOf($expectedType, Artisan::all());
+ }
+
+}
diff --git a/tests/Console/KernelTest.php b/tests/Console/KernelTest.php
new file mode 100644
--- /dev/null
+++ b/tests/Console/KernelTest.php
@@ -0,0 +1,83 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Console;
+
+use Nasqueron\Notifications\Tests\TestCase;
+
+use Artisan;
+use File;
+
+class KernelTest extends TestCase {
+ /**
+ * The actual list of services providers
+ *
+ * @var string[]
+ */
+ private $commands;
+
+ /**
+ * The service providers' namespace
+ *
+ * @var string
+ */
+ private $namespace;
+
+ public function setUp () {
+ parent::setUp();
+
+ $this->commands = Artisan::all();
+ $this->namespace = $this->app->getInstance()->getNamespace()
+ . 'Console\\Commands\\';
+ }
+
+ public function testOmittedFiles () {
+ $files = File::allFiles(app_path('Console/Commands'));
+
+ foreach ($files as $file) {
+ $class = $this->namespace . $file->getBasename('.php');
+ $this->assertArrayContainsInstanceOf(
+ $class,
+ $this->commands,
+ "The class $class should be added to app/Console/Kernel.php."
+ );
+ }
+ }
+
+ ///
+ /// Custom assertions
+ ///
+
+ /**
+ * Asserts the specified array contains an element of an expected type.
+ *
+ * @param mixed $expectedType The type to find among the array elements
+ * @param array $haystack The array where to find
+ * @param string $message The test message
+ */
+ public static function assertArrayContainsInstanceOf ($expectedType, $haystack, $message = '') {
+ self::assertThat(
+ self::arrayContainsInstanceOf($expectedType, $haystack),
+ self::isTrue(),
+ $message
+ );
+ }
+
+ /**
+ * Determines if the specified array contains at least one instance of the
+ * specified type.
+ *
+ * @param mixed $expectedType The type to find among the array elements
+ * @param array $haystack The array where to find
+ * @return bool
+ */
+ protected static function arrayContainsInstanceOf ($expectedType, $haystack) {
+ foreach ($haystack as $item) {
+ if ($item instanceof $expectedType) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Mar 11, 15:25 (20 h, 48 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2473119
Default Alt Text
D240.diff (4 KB)
Attached To
Mode
D240: Tests for console commands
Attached
Detach File
Event Timeline
Log In to Comment