for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Port\Elasticsearch\Tests;
use Port\Elasticsearch\BulkWriter;
use Elasticsearch\Client;
use PHPUnit\Framework\TestCase;
class BulkWriterTest extends TestCase
{
protected function setup()
$this->client = $this->prophesize(Client::class);
client
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
class MyClass { } $x = new MyClass(); $x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:
class MyClass { public $foo; } $x = new MyClass(); $x->foo = true;
$this->writer = new BulkWriter($this->client->reveal(), ['_index' => 'foo']);
writer
$this->reflection = new \ReflectionProperty(BulkWriter::class, 'items');
reflection
$this->reflection->setAccessible(true);
}
public function testPrepare()
$item = ['foo' => 'bar'];
$this->writer->writeItem($item);
$this->assertSame([$item], $this->reflection->getValue($this->writer));
public function testFinish()
$this->reflection->setValue($this->writer, [
['foo' => 'bar']
]);
$this->client->bulk([
'_index' => 'foo',
'body' => [[
'foo' => 'bar'
]]
])->shouldBeCalled();
$this->writer->finish();
$this->assertCount(0, $this->reflection->getValue($this->writer));
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: