PHP code example of jokersk / sonata

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

    

jokersk / sonata example snippets


use Sonata\Traits\LetsPlaySonata;

class SomeTest extends TestCase
{
    use LetsPlaySonata, RefreshDatabase;

    ...
}

$this->create(Post::class);



$post = $this->create(Post::class)->getCreated();


public function comments()

{
    return $this->hasMany(Comment::class);
}


$post = Post::factory()->create();
$comment = Comment::factory()->create(['post_id' => $post->id]);



$this->create(Post::class)->with(Comment::class);


[$post, $comment] = $this->create(Post::class)->with(Comment::class)->get([Post::class, Comment::class]);

[$post, $comment] = $this->create(Post::class)->with(Comment::class)->get();


$this->create(Post::class, [
    'title' => 'abc',
    'body' => 'hi'
]);

$this->set([
    'title' => 'abc',
    'body' => 'hi'
])->create(Post::class);

$this->create(Post::class)->with(Comment::class, [
    'body' => 'foo'
]);

$this->create(Post::class)->by('activeComments')->with(Comment::class);

$post = Post::factory()->create();
$comment = $this->createFrom($post)->with(Comment::class)->get(Comment::class);

$foo = Sonata::createMock('where()->first()->content', 'hello');