PHP code example of mpndev / d8tdd
1. Go to this page and download the library: Download mpndev/d8tdd library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mpndev / d8tdd example snippets
$this->factory(Node::class)->make();
$this->jsonRequest('http://localhost/some/endpoint')
->using('POST')
->send();
$this->factory(Node::class)->define('project', [
'type' => 'project',
'title' => 'Some Project Title'
]);
$this->factory(Node::class)->define('project', [
'type' => 'project',
'title' => $this->faker->name,
]);
$project = $this->factory(Node::class)->make('project');
$project->bundle(); // will return 'project'
$project->get('title')->getString(); // will return 'Some Project Title'
$project = $this->factory(Node::class)->make('project', [
'title' => 'Some Another Title'
'field_something' => 'Something'
]);
$project->bundle(); // will return 'project'
$project->get('title')->getString(); // will return 'Some Another Title'
$project->get('field_something')->getString(); // will return 'Something'
$projects = $this->factory(Node::class, 15)->make('project');
$this->factory(Node::class)->create('project');
$project = $this->factory(Node::class)->make('project');
//Do something...
$project->save()
/**
* make
*/
$project = $this->factory(Node::class)->make('project', [], function($project_instance){
$project_instance->get('field_environments')->appendItem($this->factory(Paragraph::class)->create('environment'));
return $project_instance;
});
/**
* create
*/
$project = $this->factory(Node::class)->create('project', [], function($project_instance){
$project_instance->get('field_environments')->appendItem($this->factory(Paragraph::class)->create('environment'));
return $project_instance;
});
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('GET')
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('POST')
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('PUT')
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('PATCH')
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('DELETE')
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('POST')
->withCookie($some_cookie)
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('POST')
->withContent($some_content)
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('POST')
->withServer($some_server)
->send();
$response = $this->httpRequest('http://localhost/some/endpoint')
->using('POST')
->withFiles($some_files)
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('GET')
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('POST')
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('PUT')
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('PATCH')
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('DELETE')
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('POST')
->withCookie($some_cookie)
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('POST')
->withContent($some_content)
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('POST')
->withServer($some_server)
->send();
$response = $this->jsonRequest('http://localhost/some/endpoint')
->using('POST')
->withFiles($some_files)
->send();
php ./vendor/mpndev/d8tdd/src/generate.php make:kerneltest my_module
php ./vendor/mpndev/d8tdd/src/generate.php make:kerneltest MyModule