"value":"\n <p>Test cases are usually split into two or three sections - \"Arrange, Act, Assert\" or \"Given, When, Then\".<\/p>\n\n<p>If the test has a prerequisite, such as some users or content to be created or in a given state, you create the required environment for the test. With unit tests, this would include mocking any dependencies you need to use.<\/p>\n\n<p>Then you perform an action on the subject under test and, finally, assert that the system is in the desired state.<\/p>\n\n<p>Maybe a user was pending initially, and they're active after running a command or a cron task. You can assert the initial state of the user as well as the final state to ensure the action did what it was supposed to do.<\/p>\n\n<h2 id=\"option-1\">Option 1<\/h2>\n\n<p>To help me get started, I'll sometimes write a test like this with placeholders to separate the test into its separate stages:<\/p>\n\n<pre><code class=\"language-php\">\/** @test *\/\nfunction should_activate_a_pending_user(): void {\n \/\/ Arrange.\n\n \/\/ Act.\n\n \/\/ Assert.\n}\n<\/code><\/pre>\n\n<p>This makes me think about the different stages and what each might need to contain.<\/p>\n\n<h2 id=\"option-2\">Option 2<\/h2>\n\n<p>Or I might write it out in the \"Given, When, Then\" format:<\/p>\n\n<pre><code class=\"language-php\">\/** @test *\/\nfunction should_activate_a_pending_user(): void {\n \/\/ Given I have a user.\n \/\/ And the user is pending.\n\n \/\/ When I run the user update command.\n\n \/\/ Then the user should no longer be 'pending'.\n \/\/ And the user status should be 'active'.\n}\n<\/code><\/pre>\n\n<p>This takes a little longer to write but feels more familiar if you're used to a behavioural testing framework like Behat.<\/p>\n\n<p>Either way, sometimes, I'll remove the comments once I've written the code around them or leave them to provide additional context.<\/p>\n\n ",
"format":"full_html",
"processed":"\n <p>Test cases are usually split into two or three sections - \"Arrange, Act, Assert\" or \"Given, When, Then\".<\/p>\n\n<p>If the test has a prerequisite, such as some users or content to be created or in a given state, you create the required environment for the test. With unit tests, this would include mocking any dependencies you need to use.<\/p>\n\n<p>Then you perform an action on the subject under test and, finally, assert that the system is in the desired state.<\/p>\n\n<p>Maybe a user was pending initially, and they're active after running a command or a cron task. You can assert the initial state of the user as well as the final state to ensure the action did what it was supposed to do.<\/p>\n\n<h2 id=\"option-1\">Option 1<\/h2>\n\n<p>To help me get started, I'll sometimes write a test like this with placeholders to separate the test into its separate stages:<\/p>\n\n<pre><code class=\"language-php\">\/** @test *\/\nfunction should_activate_a_pending_user(): void {\n \/\/ Arrange.\n\n \/\/ Act.\n\n \/\/ Assert.\n}\n<\/code><\/pre>\n\n<p>This makes me think about the different stages and what each might need to contain.<\/p>\n\n<h2 id=\"option-2\">Option 2<\/h2>\n\n<p>Or I might write it out in the \"Given, When, Then\" format:<\/p>\n\n<pre><code class=\"language-php\">\/** @test *\/\nfunction should_activate_a_pending_user(): void {\n \/\/ Given I have a user.\n \/\/ And the user is pending.\n\n \/\/ When I run the user update command.\n\n \/\/ Then the user should no longer be 'pending'.\n \/\/ And the user status should be 'active'.\n}\n<\/code><\/pre>\n\n<p>This takes a little longer to write but feels more familiar if you're used to a behavioural testing framework like Behat.<\/p>\n\n<p>Either way, sometimes, I'll remove the comments once I've written the code around them or leave them to provide additional context.<\/p>\n\n ",