Skip to content

Instantly share code, notes, and snippets.

Avatar

Adrian Philipp adri

View GitHub Profile
@adri
adri / FixtureTestCase.php
Last active Nov 8, 2018
Symfony TestCase using fixtures and database transactions
View FixtureTestCase.php
<?php
use Doctrine\Bundle\DoctrineBundle\Registry;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\DBAL\Connection;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
class FixtureTestCase extends KernelTestCase
{
/**
@adri
adri / FixtureTestCaseUsage.php
Created Sep 26, 2018
Example fixture test case that persists objects to the database.
View FixtureTestCaseUsage.php
<?php
class ExampleTest extends FixtureTestCase
{
/**
* @test
*/
public function testSomething() : void
{
$payout = $this->fixture()->payout(function (PayoutContext $payout) {
@adri
adri / ExampleUsage.php
Created Sep 26, 2018
Example usage of specifying an objects property.
View ExampleUsage.php
<?php
$payout = Factory::create()->payout(function (PayoutContext $payout) {
$payout->payoutId = PayoutId::fromString('03f74472-0e31-4d5c-8f61-bf34bda2dcb2');
});
@adri
adri / ExampleUsageWith.php
Created Sep 26, 2018
Example usage of setting dependent objects properties without creating a new object.
View ExampleUsageWith.php
<?php
$payout = Factory::create()
->withPayment(function (PaymentContext $payment) {
$payment->amount = new Money(1337, new Currency('USD'));
})
->payout(function (PayoutContext $payout) {
$payout->payoutId = PayoutId::fromString('03f74472-0e31-4d5c-8f61-bf34bda2dcb2');
});
@adri
adri / PaymentContext.php
Created Sep 26, 2018
Example PaymentContext for creating a payment object.
View PaymentContext.php
<?php
class PaymentContext
{
/**
* @var PaymentId
*/
public $paymentId;
/**
@adri
adri / PayoutContext.php
Last active Sep 26, 2018
Example PayoutContext for using a Factory
View PayoutContext.php
<?php
class PayoutContext
{
/**
* @var PayoutId
*/
public $payoutId;
/**
@adri
adri / Factory.php
Created Sep 26, 2018
Factory that resolves dependent objects using contexts.
View Factory.php
<?php
class Factory
{
/**
* @var array
*/
private $contexts = [];
/**
@adri
adri / graphql.php
Created Feb 8, 2018
Concurrent GraphQL resolvers in PHP POC
View graphql.php
<?php
// Test this using following command
// php reactphp.php
// curl http://localhost:8080 -d '{"query": "query { echo(message: \"Hello World\") }" }'
// curl http://localhost:8080 -d '{"query": "mutation { sum(x: 2, y: 2) }" }'
require_once __DIR__ . '/../vendor/autoload.php';
use GraphQL\Executor\Promise\Adapter\ReactPromiseAdapter;
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
@adri
adri / config.yml
Last active Feb 15, 2017
Cache Doctrine metadata via opcache using DoctrineCacheBridge
View config.yml
framework:
cache:
pools:
app.cache.doctrine_metadata:
adapter: cache.adapter.php_files
doctrine:
orm:
entity_managers:
default:
@adri
adri / gist:8528349
Created Jan 20, 2014
Serialization of 'SimpleXMLElement' is not allowed' on OpenSuse 12.1
View gist:8528349
opensuse-121-x64:~/wsdl2phpgenerator(php-vcr-test-fixtures)]$ phpunit
PHPUnit 3.7.29 by Sebastian Bergmann.
Configuration read from /home/vagrant/wsdl2phpgenerator/phpunit.xml.dist
........................EEEEE
Time: 11.49 seconds, Memory: 11.75Mb
There were 5 errors: