Re-organise
Signed-off-by: Oliver Davies <oliver@oliverdavies.uk>
This commit is contained in:
parent
34a2740106
commit
6891a7517a
440 changed files with 0 additions and 16 deletions
13
test-driven-drupal/code/1-example-test.txt
Normal file
13
test-driven-drupal/code/1-example-test.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
// web/modules/custom/example/tests/src/Functional.
|
||||
|
||||
namespace Drupal\Tests\example\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
class ExampleTest extends BrowserTestBase {
|
||||
|
||||
public function testSomething() {
|
||||
$this->assertTrue(FALSE);
|
||||
}
|
||||
|
||||
}
|
6
test-driven-drupal/code/1.txt
Normal file
6
test-driven-drupal/code/1.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
# drupalcon.info.yml
|
||||
|
||||
name: DrupalCon demo
|
||||
type: module
|
||||
core_version_requirement: ^10
|
||||
package: DrupalCon
|
30
test-driven-drupal/code/10.txt
Normal file
30
test-driven-drupal/code/10.txt
Normal file
|
@ -0,0 +1,30 @@
|
|||
// start code
|
||||
namespace Drupal\drupalcon\Repository;
|
||||
|
||||
final class ArticleRepository {
|
||||
|
||||
public function getAll(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
// end code
|
||||
|
||||
// start output
|
||||
F 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.266, Memory: 6.00 MB
|
||||
|
||||
There was 1 failure:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::it_returns_blog_posts
|
||||
Failed asserting that actual size 0 matches expected size 1.
|
||||
// end output
|
||||
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:20
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
FAILURES!
|
||||
Tests: 1, Assertions: 5, Failures: 1.
|
47
test-driven-drupal/code/11.txt
Normal file
47
test-driven-drupal/code/11.txt
Normal file
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
// start code 1
|
||||
namespace Drupal\drupalcon\Repository;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
|
||||
final class ArticleRepository {
|
||||
|
||||
private EntityStorageInterface $nodeStorage;
|
||||
|
||||
public function __construct(
|
||||
private EntityTypeManagerInterface $entityTypeManager,
|
||||
) {
|
||||
$this->nodeStorage = $this->entityTypeManager->getStorage('node');
|
||||
} // end code 1
|
||||
|
||||
// start code 2
|
||||
public function getAll(): array {
|
||||
return $this->nodeStorage->loadMultiple();
|
||||
}
|
||||
|
||||
}
|
||||
// end code 2
|
||||
|
||||
---
|
||||
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.401, Memory: 6.00 MB
|
||||
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::it_returns_blog_posts
|
||||
ArgumentCountError: Too few arguments to function Drupal\drupalcon\Repository\ArticleR
|
||||
epository::__construct(), 0 passed and exactly 1 expected
|
||||
|
||||
/app/web/modules/custom/drupalcon/src/Repository/ArticleRepository.php:9
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:1140
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:586
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:531
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:15
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 4, Errors: 1.
|
41
test-driven-drupal/code/12.txt
Normal file
41
test-driven-drupal/code/12.txt
Normal file
|
@ -0,0 +1,41 @@
|
|||
// start services1
|
||||
# drupalcon.services.yml
|
||||
|
||||
services:
|
||||
Drupal\drupalcon\Repository\ArticleRepository:
|
||||
autowire: true
|
||||
// end services1
|
||||
|
||||
// start services2
|
||||
services:
|
||||
Drupal\drupalcon\Repository\ArticleRepository:
|
||||
arguments:
|
||||
- '@entity_type.manager'
|
||||
// end services2
|
||||
|
||||
---
|
||||
|
||||
// start output
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.405, Memory: 6.00 MB
|
||||
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::it_returns_blog_posts
|
||||
Drupal\Component\Plugin\Exception\PluginNotFoundException:
|
||||
The "node" entity type does not exist.
|
||||
// end output
|
||||
|
||||
/app/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:139
|
||||
/app/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:253
|
||||
/app/web/core/lib/Drupal/Core/Entity/EntityTypeManager.php:192
|
||||
/app/web/modules/custom/drupalcon/src/Repository/ArticleRepository.php:12
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:1140
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:586
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:531
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:15
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 4, Errors: 1.
|
25
test-driven-drupal/code/13.txt
Normal file
25
test-driven-drupal/code/13.txt
Normal file
|
@ -0,0 +1,25 @@
|
|||
// start test
|
||||
public static $modules = [
|
||||
'drupalcon',
|
||||
'node',
|
||||
];
|
||||
// end test
|
||||
|
||||
// start output
|
||||
F 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.421, Memory: 6.00 MB
|
||||
|
||||
There was 1 failure:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::it_returns_blog_posts
|
||||
Failed asserting that actual size 0 matches expected size 1.
|
||||
// end output
|
||||
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:19
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
FAILURES!
|
||||
Tests: 1, Assertions: 9, Failures: 1.
|
40
test-driven-drupal/code/14.txt
Normal file
40
test-driven-drupal/code/14.txt
Normal file
|
@ -0,0 +1,40 @@
|
|||
namespace Drupal\Tests\drupalcon\Kernel;
|
||||
|
||||
use Drupal\drupalcon\Repository\ArticleRepository;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
|
||||
class ArticleRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
public static $modules = [
|
||||
'drupalcon',
|
||||
'node',
|
||||
];
|
||||
|
||||
// start test
|
||||
use NodeCreationTrait;
|
||||
|
||||
/** @test */
|
||||
public function it_returns_blog_posts() {
|
||||
$this->createNode(['type' => 'article']);
|
||||
|
||||
/** @var ArticleRepository */
|
||||
$repository = $this->container->get(ArticleRepository::class);
|
||||
|
||||
$articles = $repository->getAll();
|
||||
|
||||
$this->assertCount(1, $articles);
|
||||
}
|
||||
// end test
|
||||
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
// start output
|
||||
. 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.439, Memory: 6.00 MB
|
||||
|
||||
OK (1 test, 11 assertions)
|
||||
// end output
|
49
test-driven-drupal/code/15.txt
Normal file
49
test-driven-drupal/code/15.txt
Normal file
|
@ -0,0 +1,49 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\drupalcon\Kernel;
|
||||
|
||||
use Drupal\drupalcon\Repository\ArticleRepository;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\node\NodeInterface;
|
||||
use Drupal\Tests\node\Traits\NodeCreationTrait;
|
||||
|
||||
class ArticleRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
use NodeCreationTrait;
|
||||
|
||||
public static $modules = [
|
||||
'drupalcon',
|
||||
'node',
|
||||
];
|
||||
|
||||
/** @test */
|
||||
public function it_returns_blog_posts() {
|
||||
// start test
|
||||
$this->createNode([
|
||||
'title' => 'Test post',
|
||||
'type' => 'article',
|
||||
]);
|
||||
|
||||
$repository = $this->container->get(ArticleRepository::class);
|
||||
|
||||
$articles = $repository->getAll();
|
||||
|
||||
$this->assertCount(1, $articles);
|
||||
$this->assertIsObject($articles[1]);
|
||||
|
||||
$this->assertInstanceOf(NodeInterface::class, $articles[1]);
|
||||
$this->assertSame('article', $articles[1]->bundle());
|
||||
$this->assertSame('Test post', $articles[1]->label());
|
||||
// end test
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
Article Repository (Drupal\Tests\drupalcon\Kernel\ArticleRepository)
|
||||
✔ It returns blog posts
|
||||
|
||||
Time: 00:00.449, Memory: 6.00 MB
|
||||
|
||||
OK (1 test, 15 assertions)
|
36
test-driven-drupal/code/16.txt
Normal file
36
test-driven-drupal/code/16.txt
Normal file
|
@ -0,0 +1,36 @@
|
|||
// start test
|
||||
public function only_published_articles_are_returned() {
|
||||
$this->createNode(['type' => 'article', 'status' => Node::PUBLISHED]);
|
||||
$this->createNode(['type' => 'article', 'status' => Node::NOT_PUBLISHED]);
|
||||
$this->createNode(['type' => 'article', 'status' => Node::PUBLISHED]);
|
||||
$this->createNode(['type' => 'article', 'status' => Node::NOT_PUBLISHED]);
|
||||
$this->createNode(['type' => 'article', 'status' => Node::PUBLISHED]);
|
||||
|
||||
$repository = $this->container->get(ArticleRepository::class);
|
||||
|
||||
$articles = $repository->getAll();
|
||||
|
||||
$this->assertCount(3, $articles);
|
||||
} // end test
|
||||
|
||||
---
|
||||
|
||||
// start output
|
||||
.F 2 / 2 (100%)
|
||||
|
||||
Time: 00:00.903, Memory: 6.00 MB
|
||||
|
||||
There was 1 failure:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::
|
||||
only_published_articles_are_returned
|
||||
Failed asserting that actual size 5 matches expected size 3.
|
||||
// end output
|
||||
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:55
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:40
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
FAILURES!
|
||||
Tests: 2, Assertions: 22, Failures: 1.
|
37
test-driven-drupal/code/17.txt
Normal file
37
test-driven-drupal/code/17.txt
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\drupalcon\Repository;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
final class ArticleRepository {
|
||||
|
||||
private EntityStorageInterface $nodeStorage;
|
||||
|
||||
public function __construct(
|
||||
private EntityTypeManagerInterface $entityTypeManager,
|
||||
) {
|
||||
$this->nodeStorage = $this->entityTypeManager->getStorage('node');
|
||||
}
|
||||
|
||||
// start code
|
||||
public function getAll(): array {
|
||||
return $this->nodeStorage->loadByProperties([
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
]);
|
||||
}
|
||||
// end code
|
||||
|
||||
}
|
||||
|
||||
// start output
|
||||
.. 2 / 2 (100%)
|
||||
|
||||
Time: 00:00.891, Memory: 6.00 MB
|
||||
|
||||
OK (2 tests, 22 assertions)
|
||||
// end output
|
54
test-driven-drupal/code/18.txt
Normal file
54
test-driven-drupal/code/18.txt
Normal file
|
@ -0,0 +1,54 @@
|
|||
// start test
|
||||
public function nodes_are_ordered_by_date_and_returned_newest_first(): void {
|
||||
$this->createNode(['type' => 'article',
|
||||
'created' => (new DrupalDateTime('-2 days'))->getTimestamp()]);
|
||||
$this->createNode(['type' => 'article',
|
||||
'created' => (new DrupalDateTime('-1 week'))->getTimestamp()]);
|
||||
$this->createNode(['type' => 'article',
|
||||
'created' => (new DrupalDateTime('-1 hour'))->getTimestamp()]);
|
||||
$this->createNode(['type' => 'article',
|
||||
'created' => (new DrupalDateTime('-1 year'))->getTimestamp()]);
|
||||
$this->createNode(['type' => 'article',
|
||||
'created' => (new DrupalDateTime('-1 month'))->getTimestamp()]);
|
||||
|
||||
$repository = $this->container->get(ArticleRepository::class);
|
||||
$nodes = $repository->getAll();
|
||||
|
||||
$this->assertSame([3, 1, 2, 5, 4], array_keys($nodes));
|
||||
// end test
|
||||
}
|
||||
|
||||
// start output
|
||||
F 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.449, Memory: 8.00 MB
|
||||
|
||||
There was 1 failure:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::nodes_are_ordered_by_date_and_
|
||||
returned_newest_first
|
||||
Failed asserting that two arrays are identical.
|
||||
--- Expected
|
||||
+++ Actual
|
||||
@@ @@
|
||||
Array &0 (
|
||||
- 0 => 3
|
||||
- 1 => 1
|
||||
- 2 => 2
|
||||
- 3 => 5
|
||||
- 4 => 4
|
||||
+ 0 => 1
|
||||
+ 1 => 2
|
||||
+ 2 => 3
|
||||
+ 3 => 4
|
||||
+ 4 => 5
|
||||
)
|
||||
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/Constraint.php:121
|
||||
/app/vendor/phpunit/phpunit/src/Framework/Constraint/IsIdentical.php:79
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:60
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
FAILURES!
|
||||
Tests: 1, Assertions: 11, Failures: 1.
|
||||
// end output
|
43
test-driven-drupal/code/19.txt
Normal file
43
test-driven-drupal/code/19.txt
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Drupal\drupalcon\Repository;
|
||||
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\EntityTypeManagerInterface;
|
||||
use Drupal\node\NodeInterface;
|
||||
|
||||
final class ArticleRepository {
|
||||
|
||||
private EntityStorageInterface $nodeStorage;
|
||||
|
||||
public function __construct(
|
||||
private EntityTypeManagerInterface $entityTypeManager,
|
||||
) {
|
||||
$this->nodeStorage = $this->entityTypeManager->getStorage('node');
|
||||
}
|
||||
|
||||
// start code
|
||||
public function getAll(): array {
|
||||
$articles = $this->nodeStorage->loadByProperties([
|
||||
'status' => NodeInterface::PUBLISHED,
|
||||
]);
|
||||
|
||||
uasort($articles, fn (NodeInterface $a, NodeInterface $b) =>
|
||||
$b->getCreatedTime() <=> $a->getCreatedTime());
|
||||
|
||||
return $articles;
|
||||
} // end code
|
||||
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
// start output
|
||||
. 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.462, Memory: 6.00 MB
|
||||
|
||||
OK (1 test, 11 assertions)
|
||||
// end output
|
6
test-driven-drupal/code/2-test-methods.txt
Normal file
6
test-driven-drupal/code/2-test-methods.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
public function testSomething()
|
||||
|
||||
public function test_something()
|
||||
|
||||
/** @test */
|
||||
public function it_does_something()
|
13
test-driven-drupal/code/2.txt
Normal file
13
test-driven-drupal/code/2.txt
Normal file
|
@ -0,0 +1,13 @@
|
|||
// tests/src/Functional/BlogPageTest.php
|
||||
|
||||
namespace Drupal\Tests\drupalcon\Functional;
|
||||
|
||||
use Drupal\Tests\BrowserTestBase;
|
||||
|
||||
final class BlogPageTest extends BrowserTestBase {
|
||||
|
||||
public $defaultTheme = 'stark';
|
||||
|
||||
public static $modules = [];
|
||||
|
||||
}
|
41
test-driven-drupal/code/3.txt
Normal file
41
test-driven-drupal/code/3.txt
Normal file
|
@ -0,0 +1,41 @@
|
|||
// tests/src/Functional/BlogPageTest.php
|
||||
|
||||
/** @test */
|
||||
public function it_loads_the_blog_page(): void {
|
||||
$this->drupalGet('/blog');
|
||||
|
||||
$this->assertSession()->statusCodeEquals(200);
|
||||
}
|
||||
// end test
|
||||
|
||||
// start output
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:01.379, Memory: 6.00 MB
|
||||
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Functional\BlogPageTest::it_loads_the_blog_page
|
||||
Behat\Mink\Exception\ExpectationException:
|
||||
Current response status code is 404, but 200 expected.
|
||||
|
||||
/app/vendor/behat/mink/src/WebAssert.php:794
|
||||
/app/vendor/behat/mink/src/WebAssert.php:130
|
||||
/app/web/modules/custom/drupalcon/tests/src/BlogPageTest.php:16
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 2, Errors: 1.
|
||||
// end output
|
||||
|
||||
// start routing
|
||||
# drupalcon.routing.yml
|
||||
|
||||
blog.page:
|
||||
path: /blog
|
||||
defaults:
|
||||
_controller: Drupal\drupalcon\Controller\BlogPageController
|
||||
_title: Blog
|
||||
requirements:
|
||||
_permission: access content
|
||||
// end routing
|
28
test-driven-drupal/code/4.txt
Normal file
28
test-driven-drupal/code/4.txt
Normal file
|
@ -0,0 +1,28 @@
|
|||
public static $modules = ['drupalcon'];// output
|
||||
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:01.532, Memory: 6.00 MB
|
||||
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Functional\BlogPageTest::it_loads_the_blog_page
|
||||
Behat\Mink\Exception\ExpectationException:
|
||||
Current response status code is 403, but 200 expected.
|
||||
// end output
|
||||
|
||||
/app/vendor/behat/mink/src/WebAssert.php:794
|
||||
/app/vendor/behat/mink/src/WebAssert.php:130
|
||||
/app/web/modules/custom/drupalcon/tests/src/BlogPageTest.php:17
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 3, Errors: 1.
|
||||
|
||||
/app/vendor/behat/mink/src/WebAssert.php:794
|
||||
/app/vendor/behat/mink/src/WebAssert.php:130
|
||||
/app/web/tests/src/Functional/BlogPageTest.php:23
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 3, Errors: 1.
|
21
test-driven-drupal/code/5.txt
Normal file
21
test-driven-drupal/code/5.txt
Normal file
|
@ -0,0 +1,21 @@
|
|||
public static $modules = ['node', 'drupalcon']; // end code
|
||||
|
||||
// start output
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:01.906, Memory: 6.00 MB
|
||||
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Functional\BlogPageTest::it_loads_the_blog_page
|
||||
Behat\Mink\Exception\ExpectationException:
|
||||
Current response status code is 500, but 200 expected.
|
||||
// end output
|
||||
|
||||
/app/vendor/behat/mink/src/WebAssert.php:794
|
||||
/app/vendor/behat/mink/src/WebAssert.php:130
|
||||
/app/web/modules/custom/drupalcon/tests/src/BlogPageTest.php:17
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 3, Errors: 1.
|
27
test-driven-drupal/code/6.txt
Normal file
27
test-driven-drupal/code/6.txt
Normal file
|
@ -0,0 +1,27 @@
|
|||
// start code
|
||||
// src/Controller/BlogPageController.php
|
||||
|
||||
namespace Drupal\drupalcon\Controller;
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
final class BlogPageController {
|
||||
|
||||
public function __invoke(): array {
|
||||
return [];
|
||||
}
|
||||
|
||||
}
|
||||
// end code
|
||||
|
||||
// start output
|
||||
. 1 / 1 (100%)
|
||||
|
||||
Time: 00:01.916, Memory: 6.00 MB
|
||||
|
||||
OK (1 test, 3 assertions)
|
||||
|
||||
Task completed in 0m2.147s
|
||||
// end output
|
||||
|
||||
Task completed in 0m2.124s
|
61
test-driven-drupal/code/7.txt
Normal file
61
test-driven-drupal/code/7.txt
Normal file
|
@ -0,0 +1,61 @@
|
|||
// start test
|
||||
/** @test */
|
||||
public function it_loads_the_blog_page(): void {
|
||||
$this->drupalGet('/blog');
|
||||
|
||||
$session = $this->assertSession();
|
||||
$session->statusCodeEquals(200);
|
||||
|
||||
$session->responseContains('<h1>Blog</h1>');
|
||||
$session->pageTextContains('Welcome to my blog!');
|
||||
}
|
||||
// end test
|
||||
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:02.101, Memory: 6.00 MB
|
||||
|
||||
// start output
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Functional\BlogPageTest::it_loads_the_blog_page
|
||||
Behat\Mink\Exception\ResponseTextException:
|
||||
The text "Welcome to my blog!" was not found anywhere in the text
|
||||
of the current page.
|
||||
// end output
|
||||
|
||||
/app/vendor/behat/mink/src/WebAssert.php:907
|
||||
/app/vendor/behat/mink/src/WebAssert.php:293
|
||||
/app/web/modules/custom/drupalcon/tests/src/Functional/BlogPageTest.php:17
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 3, Errors: 1.
|
||||
|
||||
// start code
|
||||
namespace Drupal\drupalcon\Controller;
|
||||
|
||||
use Drupal\Core\StringTranslation\StringTranslationTrait;
|
||||
|
||||
class BlogPageController {
|
||||
|
||||
use StringTranslationTrait;
|
||||
|
||||
public function __invoke(): array {
|
||||
return [
|
||||
'#markup' => $this->t('Welcome to my blog!'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
// end code
|
||||
|
||||
// start output2
|
||||
. 1 / 1 (100%)
|
||||
|
||||
Time: 00:01.911, Memory: 6.00 MB
|
||||
|
||||
OK (1 test, 3 assertions)
|
||||
// end output2
|
||||
|
||||
Task completed in 0m2.124s
|
43
test-driven-drupal/code/8.txt
Normal file
43
test-driven-drupal/code/8.txt
Normal file
|
@ -0,0 +1,43 @@
|
|||
// start code
|
||||
// tests/src/ArticleRepositoryTest.php
|
||||
|
||||
namespace Drupal\Tests\drupalcon\Kernel;
|
||||
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
|
||||
class ArticleRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
/** @test */
|
||||
public function it_returns_blog_posts(): void {
|
||||
$repository = $this->container->get(ArticleRepository::class);
|
||||
|
||||
$this->assertCount(1, $repository->getAll());
|
||||
}// end code
|
||||
|
||||
}
|
||||
|
||||
---
|
||||
|
||||
// start output
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.405, Memory: 6.00 MB
|
||||
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::it_returns_blog_posts
|
||||
Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException:
|
||||
You have requested a non-existent service
|
||||
"Drupal\Tests\drupalcon\Kernel\ArticleRepository".
|
||||
// end output
|
||||
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:992
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:568
|
||||
/app/vendor/symfony/dependency-injection/ContainerBuilder.php:531
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:11
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 4, Errors: 1.
|
||||
|
||||
Time: 00:00.409, Memory: 8.00 MB
|
61
test-driven-drupal/code/9.txt
Normal file
61
test-driven-drupal/code/9.txt
Normal file
|
@ -0,0 +1,61 @@
|
|||
// start code
|
||||
// src/Repository/ArticleNodeRepository.php
|
||||
|
||||
namespace Drupal\drupalcon\Repository;
|
||||
|
||||
final class ArticleRepository {
|
||||
}
|
||||
// end code
|
||||
|
||||
---
|
||||
|
||||
// start services
|
||||
# drupalcon.services.yml
|
||||
|
||||
services:
|
||||
Drupal\drupalcon\Repository\ArticleRepository: ~
|
||||
// end services
|
||||
|
||||
---
|
||||
|
||||
namespace Drupal\Tests\drupalcon\Kernel;
|
||||
|
||||
use Drupal\drupalcon\Repository\ArticleRepository;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
|
||||
class ArticleRepositoryTest extends EntityKernelTestBase {
|
||||
|
||||
// start test
|
||||
public static $modules = [
|
||||
'drupalcon',
|
||||
];
|
||||
|
||||
/** @test */
|
||||
public function it_returns_blog_posts() {
|
||||
/** @var ArticleRepository */
|
||||
$repository = $this->container->get(ArticleRepository::class);
|
||||
|
||||
$articles = $repository->getAll();
|
||||
|
||||
$this->assertCount(1, $articles);
|
||||
}
|
||||
// end test
|
||||
|
||||
}
|
||||
|
||||
// start output
|
||||
E 1 / 1 (100%)
|
||||
|
||||
Time: 00:00.403, Memory: 6.00 MB
|
||||
|
||||
There was 1 error:
|
||||
|
||||
1) Drupal\Tests\drupalcon\Kernel\ArticleRepositoryTest::it_returns_blog_posts
|
||||
Error: Call to undefined method Drupal\drupalcon\Repository\ArticleRepository::getAll()
|
||||
|
||||
/app/web/modules/custom/drupalcon/tests/src/ArticleRepositoryTest.php:18
|
||||
/app/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
|
||||
|
||||
ERRORS!
|
||||
Tests: 1, Assertions: 4, Errors: 1.
|
||||
// end output
|
Loading…
Add table
Add a link
Reference in a new issue