Add php opening tags, re-add images
This commit is contained in:
parent
8db291bfca
commit
ba40104834
21
README.rst
21
README.rst
|
@ -300,6 +300,8 @@ As this functionality is provided by Drupal core by default, this should pass au
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
/** @test */
|
||||
public function the_admin_page_is_not_accessible_to_anonymous_users() {
|
||||
$this->drupalGet('admin');
|
||||
|
@ -318,6 +320,8 @@ The ``BrowserTestBase`` class gives access to a number of helper methods, includ
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
/** @test */
|
||||
public function the_admin_page_is_accessible_by_admin_users() {
|
||||
$adminUser = $this->createUser([
|
||||
|
@ -809,6 +813,8 @@ Let's start with a new test, this time with three article nodes:
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
/** @test */
|
||||
public function nodes_that_are_not_articles_are_not_returned() {
|
||||
$this->createNode(['type' => 'article'])->save();
|
||||
|
@ -1178,6 +1184,8 @@ For the first test case, let's ensure that the title is returned.
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
/** @test */
|
||||
public function it_gets_the_title() {
|
||||
$post = new Post();
|
||||
|
@ -1196,6 +1204,8 @@ Within the ``Post`` class, add a ``getTitle()`` method which will return a strin
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
public function getTitle(): string {
|
||||
return '';
|
||||
}
|
||||
|
@ -1214,6 +1224,8 @@ To get the post's title, we need to add a constructor to the ``Post`` class whic
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
class Post {
|
||||
|
||||
private $node;
|
||||
|
@ -1230,10 +1242,7 @@ To get the post's title, we need to add a constructor to the ``Post`` class whic
|
|||
|
||||
This test will fail as we need to update the test to include the node:
|
||||
|
||||
ArgumentCountError: Too few arguments to function
|
||||
Drupal\_module::\_\_construct(), 0 passed in
|
||||
/home/opdavies/Code/Personal/workshop-drupal-automated-testing-code/web/modules/custom/my\_module/tests/src/Unit/Entity/PostTest.php
|
||||
on line 12 and exactly 1 expected
|
||||
ArgumentCountError: Too few arguments to function Drupal\_module::\_\_construct(), 0 passed in /home/opdavies/Code/Personal/workshop-drupal-automated-testing-code/web/modules/custom/my\_module/tests/src/Unit/Entity/PostTest.php on line 12 and exactly 1 expected
|
||||
|
||||
Mocking the article node
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
@ -1242,6 +1251,8 @@ As we are working with a unit test, we can't interact with the database in the s
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
$node = $this->createMock(NodeInterface::class);
|
||||
|
||||
$node->expects($this->once())
|
||||
|
@ -1273,6 +1284,8 @@ Currently any node is able to be passed to the ``Post`` class. Let's ensure that
|
|||
|
||||
.. code:: php
|
||||
|
||||
<?php
|
||||
|
||||
/** @test */
|
||||
public function it_throws_an_exception_if_the_node_is_not_an_article() {
|
||||
$node = $this->createMock(NodeInterface::class);
|
||||
|
|
BIN
docs/images/1.png
Normal file
BIN
docs/images/1.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 179 KiB |
BIN
docs/images/2.png
Normal file
BIN
docs/images/2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 186 KiB |
BIN
docs/images/3.png
Normal file
BIN
docs/images/3.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 238 KiB |
Loading…
Reference in a new issue