Skip to content

Instantly share code, notes, and snippets.

View sergekukharev's full-sized avatar

Sergei Kukhariev sergekukharev

View GitHub Profile
<?php
class DummyAuthorizer implements Authorizer {
public function authorize($username, $password) {
return null;
}
}
<?php
class AcceptingAuthorizerStub implements Authorizer {
public function authorize($username, $password) {
return true;
}
}
<?php
class AcceptingAuthorizerSpy implements Authorizer {
public $authorizeWasCalled = false;
public authorize($username, $password) {
$this->authorizeWasCalled = true;
return true;
}
}
<?php
class AuthorizerFake implements Authorizer {
public $allowedUsers = [
'test_user' => '123456',
'test_admin' => '123456'
];
public authorize($username, $password) {
return array_key_exists($this->allowedUsers, $username)
&& $this->allowedUsers[$username] === $password;
<?php
class Bob_Validator_BooleanTest extends PHPUnit_Framework_TestCase
{
public function setUp() {
$this->authorizerMock = $this->getMock(Authorizer::class);
$this->authorizerMock->expects($this->once())
->method('authorize')->willReturn(true);
}
@sergekukharev
sergekukharev / README.md
Created December 31, 2021 16:19
Spark Java server starter

Spark Java server starter

Good to use with unit/integration tests of Spark Java app.

Warning!

Spark Java is pretty much dead

Configuration

Latency Comparison Numbers (~2012)

Name
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cachereference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns 3 us