@@ -4,19 +4,29 @@ Sharp provides a fluent testing API to help you test your Sharp code. These asse
44
55## The ` SharpAssertions ` trait
66
7- To use Sharp's testing helpers, include the ` Code16\Sharp\Utils\Testing\SharpAssertions ` trait in your test class:
7+ To use Sharp's testing helpers, include the ` Code16\Sharp\Utils\Testing\SharpAssertions ` trait in your TestCase class:
88
99``` php
1010use Code16\Sharp\Utils\Testing\SharpAssertions;
1111
12- class PostFormTest extends TestCase
12+ abstract class TestCase extends BaseTestCase
1313{
1414 use SharpAssertions;
1515
1616 // ...
1717}
1818```
1919
20+ or in ` Pest.php ` :
21+
22+ ``` php
23+ use Code16\Sharp\Utils\Testing\SharpAssertions;
24+
25+ pest()
26+ ->extend(\Tests\TestCase::class)
27+ ->use(SharpAssertions::class)
28+ ```
29+
2030## Authentication
2131
2232### ` loginAsSharpUser($user) `
@@ -68,31 +78,46 @@ You can call an Entity Command directly from the list:
6878
6979``` php
7080$this->sharpList(Post::class)
71- ->callEntityCommand(ExportPosts::class, ['format' => 'csv'])
81+ ->entityCommand(ExportPosts::class)
82+ ->post()
7283 ->assertOk()
7384 ->assertReturnsDownload('posts.csv');
7485```
7586
87+ If the command has a form, you can test it:
88+
89+ ``` php
90+ $this->sharpList(Post::class)
91+ ->entityCommand(ExportPosts::class)
92+ ->getForm()
93+ ->post(['format' => 'csv'])
94+ ->assertOk();
95+ ```
96+
7697### Instance Commands
7798
7899Similarly, you can call an Instance Command:
79100
80101``` php
81102$this->sharpList(Post::class)
82- ->callInstanceCommand(1, PublishPost::class)
103+ ->instanceCommand(PublishPost::class, 1)
104+ ->post()
83105 ->assertOk()
84106 ->assertReturnsReload();
85107```
86108
87109### Multi-step Commands (Wizards)
88110
89- For commands that have multiple steps, you can use ` callNextStep ()` :
111+ For commands that have multiple steps, you can use ` getNextStepForm ()` :
90112
91113``` php
92114$this->sharpList(Post::class)
93- ->callEntityCommand(MyWizardCommand::class, ['step1_data' => 'value'])
115+ ->entityCommand(MyWizardCommand::class)
116+ ->getForm()
117+ ->post(['step1_data' => 'value'])
94118 ->assertReturnsStep('step2')
95- ->callNextStep(['step2_data' => 'value'])
119+ ->getNextStepForm()
120+ ->post(['step2_data' => 'value'])
96121 ->assertOk();
97122```
98123
@@ -118,7 +143,8 @@ $this->sharpShow(Post::class, 1)
118143
119144``` php
120145$this->sharpShow(Post::class, 1)
121- ->callInstanceCommand(PublishPost::class)
146+ ->instanceCommand(PublishPost::class)
147+ ->post()
122148 ->assertOk();
123149```
124150
@@ -193,7 +219,8 @@ $this->sharpDashboard(MyDashboard::class)
193219
194220``` php
195221$this->sharpDashboard(MyDashboard::class)
196- ->callDashboardCommand(RefreshStats::class)
222+ ->dashboardCommand(RefreshStats::class)
223+ ->post()
197224 ->assertOk();
198225```
199226
@@ -219,22 +246,3 @@ $this->sharpShow(User::class, 1)
219246 ->get()
220247 ->assertOk();
221248```
222-
223- ## Advanced: Breadcrumbs and Context
224-
225- Most of the time, Sharp handles the breadcrumb automatically. However, you might need to simulate a specific breadcrumb context.
226-
227- ### ` withSharpBreadcrumb(Closure $callback) `
228-
229- ``` php
230- use Code16\Sharp\Utils\Links\BreadcrumbBuilder;
231-
232- $this->withSharpBreadcrumb(function (BreadcrumbBuilder $builder) {
233- return $builder
234- ->appendEntityList(Category::class)
235- ->appendShowPage(Category::class, 1);
236- })
237- ->sharpShow(Post::class, 1)
238- ->get()
239- ->assertOk();
240- ```
0 commit comments