Re-add syntax highlighting to daily emails and

...ATDC lessons
This commit is contained in:
Oliver Davies 2024-02-18 01:35:59 +00:00
parent 0d9bb37503
commit 5fbf48d9ac
48 changed files with 186 additions and 165 deletions

View file

@ -22,7 +22,7 @@ I've also seen Unit tests that are very tightly coupled to the implementation, s
Based on what you've learned so far, let's write a Unit test that we'd expect to pass:
```php
```language-php
<?php
namespace Drupal\Tests\atdc\Unit;
@ -58,7 +58,7 @@ Update the test to create a mock version of `NodeInterface` instead.
As the mock an instance of `NodeInterface`, it satisfies the assertion and the test passes.
```php
```language-php
/** @test */
public function it_wraps_a_post(): void {
$node = $this->createMock(NodeInterface::class);
@ -69,7 +69,7 @@ public function it_wraps_a_post(): void {
Next, add an assertion to ensure the bundle is correct:
```php
```language-php
self::assertSame('post', $node->bundle());
```
@ -81,7 +81,7 @@ Because you're using a mock, all methods will return `NULL`.
To get this to pass, you need to define what `$this->bundle()` will return:
```php
```language-php
$node->method('bundle')->willReturn('post');
```
@ -97,7 +97,7 @@ Within the test, instantiate a new `Postwrapper` class that takes the node as an
Then, add an assertion that a `getType()` method should return `post`.
```php
```language-php
$wrapper = new PostWrapper($node);
self::assertSame('post', $wrapper->getType());
@ -105,7 +105,7 @@ self::assertSame('post', $wrapper->getType());
Next, create a `PostWrapper` class with the `getType()` method:
```php
```language-php
<?php
namespace Drupal\atdc;
@ -132,7 +132,7 @@ We've tested that the `PostWrapper` works with post nodes, but let's also ensure
Create a new test that creates a mock node and returns `page` as the bundle:
```php
```language-php
/**
* @test
* @testdox It can't wrap a page
@ -153,7 +153,7 @@ Before creating a new `PostWrapper`, assert that an `InvalidArgumentException` s
To fix it, within the constructor for `PostWrapper`, check the bundle and throw the expected Exception if the bundle is not `post`:
```php
```language-php
/**
* @throws \InvalidArgumentException
*/