Skip to content

Commit

Permalink
new docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vfshera committed Oct 6, 2023
1 parent 05a14ae commit d56e35a
Show file tree
Hide file tree
Showing 91 changed files with 47,905 additions and 4 deletions.
2 changes: 1 addition & 1 deletion assets/css/highlight.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.hljs {
color: #c9d1d9;
background: #0d1117;
/* background: #0d1117; */
}

.hljs-doctag,
Expand Down
584 changes: 584 additions & 0 deletions assets/docs/html/10.x/artisan.html

Large diffs are not rendered by default.

608 changes: 608 additions & 0 deletions assets/docs/html/10.x/authentication.html

Large diffs are not rendered by default.

676 changes: 676 additions & 0 deletions assets/docs/html/10.x/authorization.html

Large diffs are not rendered by default.

1,559 changes: 1,559 additions & 0 deletions assets/docs/html/10.x/billing.html

Large diffs are not rendered by default.

1,260 changes: 1,260 additions & 0 deletions assets/docs/html/10.x/blade.html

Large diffs are not rendered by default.

828 changes: 828 additions & 0 deletions assets/docs/html/10.x/broadcasting.html

Large diffs are not rendered by default.

367 changes: 367 additions & 0 deletions assets/docs/html/10.x/cache.html

Large diffs are not rendered by default.

930 changes: 930 additions & 0 deletions assets/docs/html/10.x/cashier-paddle.html

Large diffs are not rendered by default.

3,030 changes: 3,030 additions & 0 deletions assets/docs/html/10.x/collections.html

Large diffs are not rendered by default.

202 changes: 202 additions & 0 deletions assets/docs/html/10.x/configuration.html

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions assets/docs/html/10.x/console-tests.html
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&#39;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&#39;s explore how to make assertions regarding an Artisan command&#39;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>-&gt;<span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">&#x27;inspire&#x27;</span>)-&gt;<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>-&gt;<span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">&#x27;inspire&#x27;</span>)-&gt;<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>-&gt;<span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">&#x27;inspire&#x27;</span>)-&gt;<span class="hljs-title function_ invoke__">assertSuccessful</span>();

<span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">&#x27;inspire&#x27;</span>)-&gt;<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 &quot;mock&quot; 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">&#x27;question&#x27;</span>, function () {
<span class="hljs-variable">$name</span> = <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">ask</span>(<span class="hljs-string">&#x27;What is your name?&#x27;</span>);

<span class="hljs-variable">$language</span> = <span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">choice</span>(<span class="hljs-string">&#x27;Which language do you prefer?&#x27;</span>, [
<span class="hljs-string">&#x27;PHP&#x27;</span>,
<span class="hljs-string">&#x27;Ruby&#x27;</span>,
<span class="hljs-string">&#x27;Python&#x27;</span>,
]);

<span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">line</span>(<span class="hljs-string">&#x27;Your name is &#x27;</span>.<span class="hljs-variable">$name</span>.<span class="hljs-string">&#x27; and you prefer &#x27;</span>.<span class="hljs-variable">$language</span>.<span class="hljs-string">&#x27;.&#x27;</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>-&gt;<span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">&#x27;question&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">expectsQuestion</span>(<span class="hljs-string">&#x27;What is your name?&#x27;</span>, <span class="hljs-string">&#x27;Taylor Otwell&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">expectsQuestion</span>(<span class="hljs-string">&#x27;Which language do you prefer?&#x27;</span>, <span class="hljs-string">&#x27;PHP&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">expectsOutput</span>(<span class="hljs-string">&#x27;Your name is Taylor Otwell and you prefer PHP.&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">doesntExpectOutput</span>(<span class="hljs-string">&#x27;Your name is Taylor Otwell and you prefer Ruby.&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">expectsOutputToContain</span>(<span class="hljs-string">&#x27;Taylor Otwell&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">doesntExpectOutputToContain</span>(<span class="hljs-string">&#x27;you prefer Ruby&#x27;</span>)
-&gt;<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 &quot;yes&quot; or &quot;no&quot; answer, you may utilize the <code>expectsConfirmation</code> method:</p>
<pre><code><span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">&#x27;module:import&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">expectsConfirmation</span>(<span class="hljs-string">&#x27;Do you really wish to run this command?&#x27;</span>, <span class="hljs-string">&#x27;no&#x27;</span>)
-&gt;<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&#39;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&#39;s headers as its first argument and the table&#39;s data as its second argument:</p>
<pre><code><span class="hljs-variable language_">$this</span>-&gt;<span class="hljs-title function_ invoke__">artisan</span>(<span class="hljs-string">&#x27;users:all&#x27;</span>)
-&gt;<span class="hljs-title function_ invoke__">expectsTable</span>([
<span class="hljs-string">&#x27;ID&#x27;</span>,
<span class="hljs-string">&#x27;Email&#x27;</span>,
], [
[<span class="hljs-number">1</span>, <span class="hljs-string">&#x27;taylor@example.com&#x27;</span>],
[<span class="hljs-number">2</span>, <span class="hljs-string">&#x27;abigail@example.com&#x27;</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&#39;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">&lt;?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>
Loading

0 comments on commit d56e35a

Please sign in to comment.