Skip to content

Instantly share code, notes, and snippets.

View cspray's full-sized avatar

Charles Sprayberry cspray

View GitHub Profile
@cspray
cspray / php-ds-stubs.php
Created June 26, 2016 01:23
A gist to create a PHP class for stubbing from a classname
<?php
declare(strict_types = 1);
/**
* @license See LICENSE file in project root
*/
require_once '/spraybot-app/vendor/autoload.php';
<?php
abstract class AsyncTestCase extends \PHPUnit\Framework\TestCase {
public function runTest() {
Loop::run(function() {
$watcherId = Loop::delay(1500, function() {
Loop::stop();
$this->fail('The asynchronous test was expected to finish before the 1500 millisecond time limit');
});
@cspray
cspray / aysnc-test-example.php
Created February 9, 2019 15:52
AsyncTestCase example with amphp
<?php
// We assume that your PHPUnit bootstrap will include the appropriate class loader and setup your environment
use Amp\Delayed;
use Amp\Promise;
use Amp\PHPUnit\AsyncTestCase;
use function Amp\call;
PHPUnit 6.5.14 by Sebastian Bergmann and contributors.
E.F 3 / 3 (100%)
Time: 132 ms, Memory: 4.00MB
There was 1 error:
1) Amp\PHPUnit\Test\AsyncTestCaseTest::testThatMethodRunsInLoopContext
Error: Loop exceptionally stopped without resolving the promise
@cspray
cspray / EchoCommand.php
Last active September 22, 2019 13:48
cspray/websocket-commands Quick Start
<?php
namespace MyApp\Command;
use Amp\Promise;
use Amp\Websocket\Client;
use Cspray\WebsocketCommands\ClientPayload;
use Cspray\WebsocketCommands\WebsocketCommand;
use function Amp\Promise\call;

Keybase proof

I hereby claim:

  • I am cspray on github.
  • I am cspray (https://keybase.io/cspray) on keybase.
  • I have a public key ASDgKvQd1ACmkJh6ME2WlXVdnigsEpwUUTk4BZF5Xbbjrwo

To claim this, I am signing this object:

<?php
require_once __DIR__ . '/vendor/autoload.php';
use YourNamespace\Enums\Compass;
$north = Compass::North();
$south = Compass::South();
$east = Compass::East();
$west = Compass::West();
<?php
namespace YourNamespace\Enums;
use Cspray\Yape\Enum;
use Cspray\Yape\EnumTrait;
final class Compass implements Enum {
use EnumTrait;
@cspray
cspray / callable-interface.php
Last active April 1, 2022 21:24
A spike for having CallableInterfaces in PHP
<?php
// In PHP internals, maybe this is an abstract class instead?
// Maybe an attribute?
#[Attribute]
class FunctionalInterface {}
#[FunctionalInterface]
interface MyAction {
<?php
use Cspray\AnnotatedContainer\Attribute\Service;
use Cspray\AnnotatedContainer\Attribute\Inject;
use Cspray\AnnotatedContainer\ParameterStore;
use Cspray\Typiphy\Type;
class MySecretParameterStore implements ParameterStore {
public function getName() : string {