PHP code example of andreasindal / limerence

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

    

andreasindal / limerence example snippets


namespace App\Animals;

class Dog
{
    public function makeSound()
    {
        return "Woof woof!";
    }
}



use App\Animals\Dog;

test('Dog model test', function () {
    describe('function makeSound()', function () {
        it('should make a barking sound', function () {
            $dog = new Dog();

            expect($dog)->to->have->method('makeSound');

            $bark = $dog->makeSound();

            expect($bark)->to->be->a('string');
            expect($bark)->to->equal('Woof woof!');
        });
    });
});


expect($user->name)->to->equal('James');

expect($user->name)->to->be->a('string');

expect($user->age)->to->be->an('integer');

expect($user->age)->to->be('null');

expect($user)->to->have->property('username');

expect($user)->to->have->method('login');

expect($user->hobbies)->to->contain('Fishing');

expect($user->hobbies)->to->contain->value('Fishing');

expect($user->skills)->to->contain->key('Programming');

expect($user->hobbies)->to->contain(['Fishing', 'Knitting', 'Sports']);

expect($user->name)->to->not->be->a('number');

expect($user->name)->to->not->equal('John Doe');

test('/users', function () {
    describe('GET', function () {
        it('should return a list of users', function () {
            request('GET', '/users')
                ->expect(200)
                ->end(function ($err, $res) {
                    if ($err) return;

                    expect($res->body)->to->have->property('success');
                    expect($res->body->success)->to->be->a('boolean');
                    expect($res->body->success)->to->equal(true);

                    expect($res->body)->to->have->property('users');
                    expect($res->body->users)->to->be->an('array');
                });
        });
    });
});

get('/admin')
    ->expect(403) // Expects the server to respond with 403 Forbidden
    ->end(function ($err, $res) {
        // ...
    });

get('/users')
    ->protocol('https') // Sets the protocol to https
    ->expect(200)
    ->end(function ($err, $res) {
        // ...
    });

get('/users')
    ->at('myapp.dev') // Sets the hostname to myapp.dev
    ->expect(200)
    ->end(function ($err, $res) {
        // ...
    });

get('/users')
    ->on(3000) // Sets the port to 3000
    ->expect(200)
    ->end(function ($err, $res) {
        // ...
    });

get('/users')
    ->expect(200)
    ->end(function ($err, $res) {
        // ...
    });

post('/users')
    ->expect(201)
    ->send([
        'username'  => 'johnny',
        'email'     => '[email protected]',
        'password'  => 'password123',
    ]) // no json flag, data will be sent as normal form data
    ->end(function ($err, $res) {
        // ...
    });

put('/users/15')
    ->expect(200)
    ->send([
        'firstname' => 'James',
        'lastname'  => 'Smith',
    ], true) // Data will be sent as JSON
    ->end(function ($err, $res) {
        // ...
    });

delete('/users/15')
    ->expect(200)
    ->with('Authorization', 'Bearer eyJhbGciOiJIUzI1N...')
    ->end(function ($err, $res) {
        // ...
    });