Skip to content

Instantly share code, notes, and snippets.

This code snippet overrides php DuskTestCase->createBrowsers method to extends the functionality and add the elements count assertion

File tests/Browser/BaseBrowser.php

// Extend Browser Class
namespace Tests\Browser;

use Laravel\Dusk\Browser;
use PHPUnit_Framework_Assert as PHPUnit;

File: tests/TestCase.php

namespace Tests;

use Illuminate\Foundation\Testing\TestCase as BaseTestCase;

abstract class TestCase extends BaseTestCase
{
 use CreatesApplication;
DELIMITER $$
CREATE TRIGGER Prevent_User_From_Insert_Empty_Strings BEFORE INSERT ON users
FOR EACH ROW
BEGIN
   IF NEW.name = '' THEN
       SIGNAL SQLSTATE '45000';
   END IF;
END;
<?php
/**
* A better way to iterate over an collection
*/
$itemsArray = [ 1, 2, 3 ];
/**
* Legacy code
<?php
class Author
{
private $id, $membership, $posts = [];
// Pseudo code 1
public function __construct($id, $membership, $posts)