Re-add syntax highlighting to daily emails and
...ATDC lessons
This commit is contained in:
parent
0d9bb37503
commit
5fbf48d9ac
48 changed files with 186 additions and 165 deletions
|
|
@ -28,7 +28,7 @@ Instead of making HTTP requests and checking the responses, we can test the resu
|
|||
|
||||
Let's create a new test that uses the `PostNodeRepository` to find the nodes and assert we get an expected number returned.
|
||||
|
||||
```php
|
||||
```language-php
|
||||
<?php
|
||||
|
||||
namespace Drupal\Tests\atdc\Kernel;
|
||||
|
|
@ -73,7 +73,7 @@ It's defined within `atdc.services.yml`, but we need to be explicit about which
|
|||
|
||||
Create a `$modules` array within the test class and add `atdc`:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
protected static $modules = ['atdc'];
|
||||
```
|
||||
|
||||
|
|
@ -83,7 +83,7 @@ Run the tests again, and you should get a different error:
|
|||
|
||||
As well as `atdc`, you must enable the `node` module. You can do so by adding it to the `$modules` array:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
protected static $modules = ['node', 'atdc'];
|
||||
```
|
||||
|
||||
|
|
@ -111,7 +111,7 @@ Within the test, you can use `$this->createNode()` to create posts.
|
|||
|
||||
Create the three posts the test is expecting:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
// Arrange.
|
||||
$this->createNode(['type' => 'post']);
|
||||
$this->createNode(['type' => 'post']);
|
||||
|
|
@ -126,7 +126,7 @@ Next, let's assert they're returned in a specific order.
|
|||
|
||||
Update the posts to have a specific title and created date so we can specify which order we expect them to be returned in and which titles they should have:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
// Arrange.
|
||||
$this->createNode([
|
||||
'created' => (new DrupalDateTime('-1 week'))->getTimestamp(),
|
||||
|
|
@ -151,7 +151,7 @@ Note we're intentionally setting them to be in an incorrect order, to begin with
|
|||
|
||||
Next, assert that the titles are returned in the correct order.
|
||||
|
||||
```php
|
||||
```language-php
|
||||
self::assertSame(
|
||||
['Post two', 'Post one', 'Post three'],
|
||||
array_map(
|
||||
|
|
@ -165,7 +165,7 @@ For each node in `$nodes`, get its label (title) and compare them with the title
|
|||
|
||||
As expected, the test fails:
|
||||
|
||||
```plain
|
||||
```language-plain
|
||||
1) Drupal\Tests\atdc\Kernel\PostNodeRepositoryTest::testPostsAreReturnedByCreatedDate
|
||||
Failed asserting that two arrays are identical.
|
||||
--- Expected
|
||||
|
|
@ -187,7 +187,7 @@ We need to update the code within `PostNodeRepository` to fix the ordering.
|
|||
|
||||
After loading the nodes, we need to sort them.
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function findAll(): array {
|
||||
$nodeStorage = $this->entityTypeManager->getStorage('node');
|
||||
$nodes = $nodeStorage->loadMultiple();
|
||||
|
|
@ -206,7 +206,7 @@ This gets us further, but the test is still failing.
|
|||
|
||||
Whilst the order is correct, the array keys don't match what we expect:
|
||||
|
||||
```plain
|
||||
```language-plain
|
||||
1) Drupal\Tests\atdc\Kernel\PostNodeRepositoryTest::testPostsAreReturnedByCreatedDate
|
||||
Failed asserting that two arrays are identical.
|
||||
--- Expected
|
||||
|
|
@ -233,7 +233,7 @@ And, because the correct titles are still being shown, our original Functional t
|
|||
|
||||
Tip: to see the names of the tests in your output, add the `--testdox` flag to the `phpunit` command:
|
||||
|
||||
```plain
|
||||
```language-plain
|
||||
Blog Page (Drupal\Tests\atdc\Functional\BlogPage)
|
||||
✔ Blog page
|
||||
✔ Posts are visible
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue