generated from vfshera/svelte-vscode-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
91 changed files
with
47,905 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
|
||
.hljs { | ||
color: #c9d1d9; | ||
background: #0d1117; | ||
/* background: #0d1117; */ | ||
} | ||
|
||
.hljs-doctag, | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<h1>Console Tests</h1> | ||
<ul> | ||
<li><a href="#introduction">Introduction</a></li> | ||
<li><a href="#success-failure-expectations">Success / Failure Expectations</a></li> | ||
<li><a href="#input-output-expectations">Input / Output Expectations</a></li> | ||
<li><a href="#console-events">Console Events</a></li> | ||
</ul> | ||
<p><a name="introduction"></a></p> | ||
<h2>Introduction</h2> | ||
<p>In addition to simplifying HTTP testing, Laravel provides a simple API for testing your application's <a href="/docs/%7B%7Bversion%7D%7D/artisan">custom console commands</a>.</p> | ||
<p><a name="success-failure-expectations"></a></p> | ||
<h2>Success / Failure Expectations</h2> | ||
<p>To get started, let's explore how to make assertions regarding an Artisan command's exit code. To accomplish this, we will use the <code>artisan</code> method to invoke an Artisan command from our test. Then, we will use the <code>assertExitCode</code> method to assert that the command completed with a given exit code:</p> | ||
<pre><code><span class="hljs-comment">/** | ||
* Test a console command. | ||
*/</span> | ||
<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_console_command</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span> | ||
</span>{ | ||
<span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">'inspire'</span>)-><span class="hljs-title function_ invoke__">assertExitCode</span>(<span class="hljs-number">0</span>); | ||
} | ||
</code></pre><p>You may use the <code>assertNotExitCode</code> method to assert that the command did not exit with a given exit code:</p> | ||
<pre><code><span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">'inspire'</span>)-><span class="hljs-title function_ invoke__">assertNotExitCode</span>(<span class="hljs-number">1</span>); | ||
</code></pre><p>Of course, all terminal commands typically exit with a status code of <code>0</code> when they are successful and a non-zero exit code when they are not successful. Therefore, for convenience, you may utilize the <code>assertSuccessful</code> and <code>assertFailed</code> assertions to assert that a given command exited with a successful exit code or not:</p> | ||
<pre><code><span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">'inspire'</span>)-><span class="hljs-title function_ invoke__">assertSuccessful</span>(); | ||
|
||
<span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">'inspire'</span>)-><span class="hljs-title function_ invoke__">assertFailed</span>(); | ||
</code></pre><p><a name="input-output-expectations"></a></p> | ||
<h2>Input / Output Expectations</h2> | ||
<p>Laravel allows you to easily "mock" user input for your console commands using the <code>expectsQuestion</code> method. In addition, you may specify the exit code and text that you expect to be output by the console command using the <code>assertExitCode</code> and <code>expectsOutput</code> methods. For example, consider the following console command:</p> | ||
<pre><code><span class="hljs-title class_">Artisan</span>::<span class="hljs-title function_ invoke__">command</span>(<span class="hljs-string">'question'</span>, function () { | ||
<span class="hljs-variable">$name</span> = <span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">ask</span>(<span class="hljs-string">'What is your name?'</span>); | ||
|
||
<span class="hljs-variable">$language</span> = <span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">choice</span>(<span class="hljs-string">'Which language do you prefer?'</span>, [ | ||
<span class="hljs-string">'PHP'</span>, | ||
<span class="hljs-string">'Ruby'</span>, | ||
<span class="hljs-string">'Python'</span>, | ||
]); | ||
|
||
<span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">line</span>(<span class="hljs-string">'Your name is '</span>.<span class="hljs-variable">$name</span>.<span class="hljs-string">' and you prefer '</span>.<span class="hljs-variable">$language</span>.<span class="hljs-string">'.'</span>); | ||
}); | ||
</code></pre><p>You may test this command with the following test which utilizes the <code>expectsQuestion</code>, <code>expectsOutput</code>, <code>doesntExpectOutput</code>, <code>expectsOutputToContain</code>, <code>doesntExpectOutputToContain</code>, and <code>assertExitCode</code> methods:</p> | ||
<pre><code><span class="hljs-comment">/** | ||
* Test a console command. | ||
*/</span> | ||
<span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">test_console_command</span>(<span class="hljs-params"></span>): <span class="hljs-title">void</span> | ||
</span>{ | ||
<span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">'question'</span>) | ||
-><span class="hljs-title function_ invoke__">expectsQuestion</span>(<span class="hljs-string">'What is your name?'</span>, <span class="hljs-string">'Taylor Otwell'</span>) | ||
-><span class="hljs-title function_ invoke__">expectsQuestion</span>(<span class="hljs-string">'Which language do you prefer?'</span>, <span class="hljs-string">'PHP'</span>) | ||
-><span class="hljs-title function_ invoke__">expectsOutput</span>(<span class="hljs-string">'Your name is Taylor Otwell and you prefer PHP.'</span>) | ||
-><span class="hljs-title function_ invoke__">doesntExpectOutput</span>(<span class="hljs-string">'Your name is Taylor Otwell and you prefer Ruby.'</span>) | ||
-><span class="hljs-title function_ invoke__">expectsOutputToContain</span>(<span class="hljs-string">'Taylor Otwell'</span>) | ||
-><span class="hljs-title function_ invoke__">doesntExpectOutputToContain</span>(<span class="hljs-string">'you prefer Ruby'</span>) | ||
-><span class="hljs-title function_ invoke__">assertExitCode</span>(<span class="hljs-number">0</span>); | ||
} | ||
</code></pre><p><a name="confirmation-expectations"></a></p> | ||
<h4>Confirmation Expectations</h4> | ||
<p>When writing a command which expects confirmation in the form of a "yes" or "no" answer, you may utilize the <code>expectsConfirmation</code> method:</p> | ||
<pre><code><span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">'module:import'</span>) | ||
-><span class="hljs-title function_ invoke__">expectsConfirmation</span>(<span class="hljs-string">'Do you really wish to run this command?'</span>, <span class="hljs-string">'no'</span>) | ||
-><span class="hljs-title function_ invoke__">assertExitCode</span>(<span class="hljs-number">1</span>); | ||
</code></pre><p><a name="table-expectations"></a></p> | ||
<h4>Table Expectations</h4> | ||
<p>If your command displays a table of information using Artisan's <code>table</code> method, it can be cumbersome to write output expectations for the entire table. Instead, you may use the <code>expectsTable</code> method. This method accepts the table's headers as its first argument and the table's data as its second argument:</p> | ||
<pre><code><span class="hljs-variable language_">$this</span>-><span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">'users:all'</span>) | ||
-><span class="hljs-title function_ invoke__">expectsTable</span>([ | ||
<span class="hljs-string">'ID'</span>, | ||
<span class="hljs-string">'Email'</span>, | ||
], [ | ||
[<span class="hljs-number">1</span>, <span class="hljs-string">'taylor@example.com'</span>], | ||
[<span class="hljs-number">2</span>, <span class="hljs-string">'abigail@example.com'</span>], | ||
]); | ||
</code></pre><p><a name="console-events"></a></p> | ||
<h2>Console Events</h2> | ||
<p>By default, the <code>Illuminate\Console\Events\CommandStarting</code> and <code>Illuminate\Console\Events\CommandFinished</code> events are not dispatched while running your application's tests. However, you can enable these events for a given test class by adding the <code>Illuminate\Foundation\Testing\WithConsoleEvents</code> trait to the class:</p> | ||
<pre><code><span class="hljs-meta"><?php</span> | ||
|
||
<span class="hljs-keyword">namespace</span> <span class="hljs-title class_">Tests</span>\<span class="hljs-title class_">Feature</span>; | ||
|
||
<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Foundation</span>\<span class="hljs-title">Testing</span>\<span class="hljs-title">WithConsoleEvents</span>; | ||
<span class="hljs-keyword">use</span> <span class="hljs-title">Tests</span>\<span class="hljs-title">TestCase</span>; | ||
|
||
<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">ConsoleEventTest</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">TestCase</span> | ||
</span>{ | ||
<span class="hljs-keyword">use</span> <span class="hljs-title">WithConsoleEvents</span>; | ||
|
||
<span class="hljs-comment">// ...</span> | ||
} | ||
</code></pre> |
Oops, something went wrong.