PHP code example of viraj / cakephp-testdummy

1. Go to this page and download the library: Download viraj/cakephp-testdummy 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/ */

    

viraj / cakephp-testdummy example snippets


# config/TableFactory.php



$factory = \TestDummy\Definition::getInstance();



$factory = \TestDummy\Definition::getInstance();

$factory->define('Posts', function (Faker\Generator $faker) {
    return [
        'title'     => $faker->sentence,
        'author'    => $faker->name,
        'body'      => $faker->paragraph,
        'published' => true,
    ];
});

/** @test */
public function user_can_edit_a_post()
{
    $post = factory('Posts')->create();

    $this->post('/posts/edit/' . $post->id, [
        'title'     => 'Updated Post',
        'author'    => 'Updated Author',
        'body'      => 'Updated Random body text',
        'published' => true,
    ]);
        
    //Your assertions

}


namespace App\Test\TestCase;


use TestDummy\Traits\DatabaseMigrations;

class ViewPostListTest extends BaseTestCase
{
    use DatabaseMigrations;

    /** @test */
    public function user_can_see_published_posts()
    {
        factory('Posts')->create(['title' => 'Nate Emmons post']);
        factory('Posts')->create(['title' => 'Megan Danz post']);

        $this->get('/posts');
        $this->assertResponseContains('Nate Emmons post');
        $this->assertResponseContains('Megan Danz post');
    }

    /** @test */
    public function user_cannot_see_unpublished_posts()
    {
        factory('Posts')->create(['title' => 'Nate Emmons post', 'published' => false]);
        factory('Posts')->create(['title' => 'Megan Danz post', 'published' => false]);

        $this->get('/posts');
        $this->assertResponseNotContains('Nate Emmons post');
        $this->assertResponseNotContains('Megan Danz post');
    }
}

factory('Posts')->create(['title' => 'Your custom title']);

$posts = factory('Posts', 100)->create();