Skip to content
This repository has been archived by the owner on May 2, 2023. It is now read-only.

Feature php73 #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
nbproject/
sftp-*
/vendor
phpunit.xml

# many file generated by IDE
.buildpath
.classpath
.project
.settings/
.idea/
.vscode/
*.swp
*.swo
*.orig
*~
.shell_history

# force git config file to never be ignored
!.gitkeep
!.gitignore

9 changes: 6 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@
"licence" : "MIT",
"homepage" : "http://github.com/v-technologies/simpl-es/",
"require": {
"php" : ">=5.2.0"
"php" : ">=7.3.0"
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
"phpunit/phpunit": "^8.4"
},
"autoload": {
"psr-0": {"Simples": "lib/"}
}
},
"autoload-dev": {
"psr-0": { "Tests_Simples": "tests/lib" }
}
}
4 changes: 2 additions & 2 deletions lib/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*
* @param string $class Class name to load
*/
function __autoload_simples ($class) {
function autoload_simples ($class) {
$path = str_replace('_', DIRECTORY_SEPARATOR , $class);

if (file_exists(SIMPLES_ROOT . $path . '.php')) {
Expand All @@ -22,4 +22,4 @@ function __autoload_simples ($class) {
}

// Register our custom autoload method
spl_autoload_register('__autoload_simples');
spl_autoload_register('autoload_simples');
24 changes: 24 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="./tests/lib/Autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
>
<php>
<ini name="memory_limit" value="-1"/>
<env name="host" value="127.0.0.1" force="true" />
<env name="port" value="9200" force="true" />
<env name="protocol" value="http" force="true" />
</php>
<testsuites>
<testsuite name="AllTests">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 20 additions & 0 deletions tests/lib/Autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

if (!defined('SIMPLES_TESTS_ROOT')) {
define('SIMPLES_TESTS_ROOT', dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR);
}

/**
* Simples autoload method for tests.
*
* @param string $class Class name to load
*/
function autoload_simples_tests ($class) {
$path = str_replace('_', DIRECTORY_SEPARATOR , $class);
if (file_exists(SIMPLES_TESTS_ROOT . $path . '.php')) {
require_once(SIMPLES_TESTS_ROOT . $path . '.php');
}
}

// Register our custom autoload method
spl_autoload_register('autoload_simples_tests');
4 changes: 3 additions & 1 deletion tests/lib/Simples/Document/SetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');

class Simples_Document_SetTest extends PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;

class Simples_Document_SetTest extends TestCase {

public function testConstruct() {
$set = new Simples_Document_Set() ;
Expand Down
7 changes: 4 additions & 3 deletions tests/lib/Simples/DocumentTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<?php
require_once(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'bootstrap.php') ;

class Simples_DocumentTest extends PHPUnit_Framework_TestCase {
class Simples_DocumentTest extends Simples_HttpTestCase {

/**
* Set up some fixtures.
*/
public function setUp() {
protected function setUp() : void {
parent::setUp();

$this->data['standard'] = array(
'firstname' => 'Jim',
'lastname' => 'Morrison',
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/Simples/FactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
require_once(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'bootstrap.php') ;

class Simples_FactoryTest extends PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;

class Simples_FactoryTest extends TestCase {

public function testConstruct() {
$factory = new Simples_Factory() ;
Expand Down
46 changes: 46 additions & 0 deletions tests/lib/Simples/HttpTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

use PHPUnit\Framework\TestCase;

class Simples_HttpTestCase extends TestCase {

/**
* @var Simples_Transport_Http|null
*/
protected $client;

/**
* @var array
*/
protected $defaultHttpConfig = [
'host' => '127.0.0.1',
'port' => 9200,
'protocol' => 'http',
'timeout' => 1000,
'check' => true,
'index' => null,
'type' => null
];

/**
* Redefine http config from env var
* given by phpunit.xml
*/
protected function setUp() : void {
foreach ($this->defaultHttpConfig as $key => $value) {
if (getenv($key)) {
$this->defaultHttpConfig[$key] = getenv($key);
}
}
parent::setUp();
$this->client = new Simples_Transport_Http($this->getTransportHttpConfig());
}

/**
* @return []
*/
protected function getTransportHttpConfig()
{
return $this->defaultHttpConfig;
}
}
4 changes: 3 additions & 1 deletion tests/lib/Simples/PathTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?php
require_once(dirname(dirname(__FILE__)) . DIRECTORY_SEPARATOR . 'bootstrap.php') ;

class Simples_PathTest extends PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;

class Simples_PathTest extends TestCase {

public function testPath() {
$path = new Simples_Path('/root/') ;
Expand Down
8 changes: 1 addition & 7 deletions tests/lib/Simples/Request/CreateIndexTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
<?php

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');
class Simples_Request_CreateIndexTest extends Simples_HttpTestCase {

class Simples_Request_CreateIndexTest extends PHPUnit_Framework_TestCase {

public function setUp() {
$this->client = new Simples_Transport_Http() ;
}

public function testCreate() {
$this->client->config('index','test_index') ;
$request = $this->client->createIndex() ;
Expand Down
4 changes: 3 additions & 1 deletion tests/lib/Simples/Request/DefinitionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');

class Simples_Request_DefinitionTest extends PHPUnit_Framework_TestCase {
use PHPUnit\Framework\TestCase;

class Simples_Request_DefinitionTest extends TestCase {

public function testDefinition() {
try {
Expand Down
7 changes: 2 additions & 5 deletions tests/lib/Simples/Request/DeleteIndexTest.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<?php

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');

class Simples_Request_DeleteIndexTest extends PHPUnit_Framework_TestCase {
class Simples_Request_DeleteIndexTest extends Simples_HttpTestCase {

public function testDelete() {
$client = new Simples_Transport_Http();
$request = $client->deleteIndex('twitter') ;
$request = $this->client->deleteIndex('twitter') ;
$this->assertEquals(Simples_Request::DELETE, $request->method()) ;
$this->assertEquals('/twitter/', (string) $request->path()) ;
}
Expand Down
6 changes: 2 additions & 4 deletions tests/lib/Simples/Request/DeleteTest.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');

class Simples_Request_DeleteTest extends PHPUnit_Framework_TestCase {
class Simples_Request_DeleteTest extends Simples_HttpTestCase {

public function testDelete() {
$client = new Simples_Transport_Http();
$client = $this->client;
$this->assertTrue($client->index(
array(
'content' => 'Pliz, pliz, delete me !'
Expand Down
13 changes: 6 additions & 7 deletions tests/lib/Simples/Request/DeleteTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');

class Simples_Request_DeleteTypeTest extends PHPUnit_Framework_TestCase {
class Simples_Request_DeleteTypeTest extends Simples_HttpTestCase {

public $client ;

public function setUp() {
$this->client = new Simples_Transport_Http(array('index' => 'test_delete', 'type' => 'test_delete_type'));
protected function setUp() : void {
parent::setUp();
$this->client->config('index', 'test_delete');
$this->client->config('type', 'test_delete_type');
$this->client->createIndex()->execute() ;
}

Expand All @@ -24,10 +24,9 @@ public function testDelete() {
$this->assertTrue($response->ok) ;
}

public function tearDown() {
protected function tearDown() : void {
if ($this->client) {
$this->client->deleteIndex()->execute() ;
}
}

}
30 changes: 14 additions & 16 deletions tests/lib/Simples/Request/GetTest.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
<?php

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');

class Simples_Request_GetTest extends PHPUnit_Framework_TestCase {
class Simples_Request_GetTest extends Simples_HttpTestCase {

protected function setUp() : void
{
parent::setUp();
$this->client->config('index', 'twitter');
$this->client->config('type', 'tweet');
}

public function testGet() {
$client = new Simples_Transport_Http(array(
'index' => 'twitter',
'type' => 'tweet'
));
$this->client->config('index', 'twitter');
$this->client->config('type', 'tweet');

$this->assertTrue($client->index(array('content' => 'I\'m there.'), array('id' => 'test_get'))->ok) ;
$this->assertEquals('I\'m there.', $client->get('test_get')->_source->content);
$this->assertTrue($this->client->index(array('content' => 'I\'m there.'), array('id' => 'test_get'))->ok) ;
$this->assertEquals('I\'m there.', $this->client->get('test_get')->_source->content);
}

public function testMultiple() {
$client = new Simples_Transport_Http(array(
'index' => 'twitter',
'type' => 'tweet'
));

$client->index(array(
$this->client->index(array(
array('id' => '1', 'value' => 'first'),
array('id' => '2', 'value' => 'second')
), array('refresh' => true)) ;

$request = $client->get(array(1,2)) ;
$request = $this->client->get(array(1,2)) ;
$this->assertEquals('/_mget/', (string) $request->path()) ;
$body = $request->body() ;
$this->assertEquals('1', $body['docs'][0]['_id']) ;
Expand Down
16 changes: 6 additions & 10 deletions tests/lib/Simples/Request/IndexTest.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
<?php

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');

class Simples_Request_IndexTest extends PHPUnit_Framework_TestCase {
class Simples_Request_IndexTest extends Simples_HttpTestCase {

public $client ;

public function setUp() {
$this->client = new Simples_Transport_Http(array(
'index' => 'twitter',
'type' => 'tweet'
));
protected function setUp() : void {
parent::setUp();

$this->client->config('index', 'twitter');
$this->client->config('type', 'tweet');
}

public function testIndex() {
$request = new Simples_Request_Index(null, null, new Simples_Transport_Http());

$request = $this->client->index(array(
'user' => 'scharrier',
'fullname' => 'Sébastien Charrier'
Expand Down
17 changes: 7 additions & 10 deletions tests/lib/Simples/Request/MappingTest.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
<?php

require_once(dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'bootstrap.php');
class Simples_Request_MappingTest extends Simples_HttpTestCase {

class Simples_Request_MappingTest extends PHPUnit_Framework_TestCase {

public function setUp() {
$this->client = new Simples_Transport_Http(array(
'index' => 'music',
'type' => 'composers',
'log' => true
));
protected function setUp() : void {
parent::setUp();
$this->client->config('index', 'music');
$this->client->config('type', 'composers');
$this->client->config('log', true);
$this->client->createIndex()->execute() ;
}

Expand Down Expand Up @@ -72,7 +69,7 @@ public function testRealcase() {
$this->assertEquals($mapping, $response->to('array')) ;
}

public function tearDown() {
protected function tearDown() : void {
$this->client->deleteIndex()->execute() ;
}
}
Loading