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
|
|
@ -20,7 +20,7 @@ First, let's ensure that only published nodes are returned and displayed on the
|
|||
|
||||
We can do this easily with a functional test, so add a new test method to `BlogPostTest`:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function testOnlyPublishedNodesAreShown(): void {
|
||||
PostBuilder::create()
|
||||
->setTitle('Post one')
|
||||
|
|
@ -54,7 +54,7 @@ In this test, we want to create some published and unpublished posts and assert
|
|||
|
||||
To fix the error, add this function so it exists:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function isPublished(): self {
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -70,7 +70,7 @@ When using `PostBuilder` in the previous lesson, we were always providing a crea
|
|||
|
||||
Update the `getPost()` method to only set the created time if the `created` property has a value.
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function getPost(): NodeInterface {
|
||||
$post = Node::create([
|
||||
'title' => $this->title,
|
||||
|
|
@ -93,7 +93,7 @@ Now, we can see a similar error to the one before for `isNotPublished()`.
|
|||
|
||||
Again, create the simplest version of the method so the test can progress:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function isNotPublished(): self {
|
||||
return $this;
|
||||
}
|
||||
|
|
@ -112,13 +112,13 @@ Within `PostBuilder`, we need to use the `isPublished` and `isNotPublished` meth
|
|||
|
||||
First, add an `isPublished` property to the class and set it to be `TRUE` by default:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
private bool $isPublished = TRUE;
|
||||
```
|
||||
|
||||
Next, update the `isPublished()` and `isNotPublished()` methods to set the value appropriately:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function isNotPublished(): self {
|
||||
$this->isPublished = FALSE;
|
||||
|
||||
|
|
@ -136,7 +136,7 @@ Even though `isPublished` is already true by default, doing this makes it explic
|
|||
|
||||
Finally, within `getPost()`, update the code that creates the node to set the `status` property accordingly.
|
||||
|
||||
```php
|
||||
```language-php
|
||||
$post = Node::create([
|
||||
'status' => $this->isPublished,
|
||||
'title' => $this->title,
|
||||
|
|
@ -152,7 +152,7 @@ We also need to update the `PostNodeRepository` as that is responsible for loadi
|
|||
|
||||
Currently, all we're doing is this:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
$nodes = $nodeStorage->loadMultiple();
|
||||
```
|
||||
|
||||
|
|
@ -160,7 +160,7 @@ This will load all nodes, regardless of their type or status.
|
|||
|
||||
To fix this, change this to use `loadByProperties()` instead:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
$nodes = $nodeStorage->loadByProperties();
|
||||
```
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ Note: you can also use `->getQuery()` if you prefer and write the query yourself
|
|||
|
||||
For this case, let's add a property for `status` and its value to be `TRUE`:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
$nodes = $nodeStorage->loadByProperties([
|
||||
'status' => TRUE,
|
||||
]);
|
||||
|
|
@ -184,7 +184,7 @@ The other issue is all published nodes are returned, even if they aren't posts.
|
|||
|
||||
Before adding this to `PostNodeRepository`, create a new failing test for it:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
public function testOnlyPostNodesAreShown(): void {
|
||||
PostBuilder::create()->setTitle('Post one')->getPost();
|
||||
PostBuilder::create()->setTitle('Post two')->getPost();
|
||||
|
|
@ -213,7 +213,7 @@ If you run the test, it should fail as expected:
|
|||
|
||||
Now we have a failing test, let's add the extra condition to `PostNodeRepository`:
|
||||
|
||||
```php
|
||||
```language-php
|
||||
$nodes = $nodeStorage->loadByProperties([
|
||||
'status' => TRUE,
|
||||
'type' => 'post',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue