Page MenuHomeDevCentral

D240.id565.diff
No OneTemporary

D240.id565.diff

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,84 @@
+<?php
+
+namespace Nasqueron\Notifications\Tests\Console;
+
+use Nasqueron\Notifications\Tests\TestCase;
+
+use Artisan;
+use Config;
+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

Mime Type
text/plain
Expires
Tue, Mar 11, 18:39 (21 h, 13 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2473531
Default Alt Text
D240.id565.diff (4 KB)

Event Timeline