GithubHelp home page GithubHelp logo

matthiasnoback / doctrine-dbal-test-service-provider Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 8.0 15 KB

Service provider for tests in need of a Doctrine DBAL connection

License: MIT License

PHP 100.00%

doctrine-dbal-test-service-provider's Introduction

Doctrine DBAL service provider for unit tests

Build Status

This library contains a service provider to be used with a service container for PHPUnit tests.

Usage

Use the trait Noback\PHPUnitTestServiceContainer\PHPUnit\TestCaseWithDoctrineDbalConnection in your test class. You then need to implement the createSchema() and return an instance of Doctrine\DBAL\Schema\Schema.

For each test method a database connection (of instance Doctrine\DBAL\Connection) will be available. Also the schema returned by createSchema() will be created in the database. The database itself is (by default) an SQLite in-memory database, which will leave no traces on the filesystem.

<?php

use Noback\PHPUnitTestServiceContainer\PHPUnit\TestCaseWithDoctrineDbalConnection;
use Doctrine\DBAL\Schema\Schema;

final class StorageTest
{
    use TestCaseWithDoctrineDbalConnection;
    
    /**
     * @test
     */
    public function something()
    {
        $connection = $this->getConnection();

        $connection->insert('some_table', array('some_column' => 'value'));

        ...
    }

    protected function createSchema()
    {
        $schema = new Schema();

        $table = $schema->createTable('some_table');

        $table->addColumn('some_column', 'string');

        return $schema;
    }
}

Read more

doctrine-dbal-test-service-provider's People

Contributors

matthiasnoback avatar michieldilissen avatar ruudk avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

doctrine-dbal-test-service-provider's Issues

Allow PHPUnit 8

Is it possible to support PHPUnit 8 (maybe changing the requirements could suffice)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.