Skip to content

Commit

Permalink
4.1.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc-business-account committed Mar 21, 2023
1 parent 7e96209 commit 8ca8ead
Show file tree
Hide file tree
Showing 4 changed files with 158 additions and 141 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1834,6 +1834,9 @@ In a nutshell:
> Every minor version means that it adds a new functionality i.e. 1.5 -> 1.6 (new methods)
>
> Every decimal version means that it patches/fixes/refactoring a previous functionality i.e. 1.5.0 -> 1.5.1 (fix)
* 4.1.2 2023-03-21
* str_start_with() is not defined in PHP older than PHP 8.0, so I replaced.
* 4.1.1 2023-03-21
* [PdoOneCli] Update to 2.3.1.
* [composer.json] Update dependency to eftec/clione 1.26 or higher.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"eftec/validationone": "For keeping and storing the messages"
},
"require-dev": {
"phpunit/phpunit": "^9.5.13"
"phpunit/phpunit": "^8.5.13"
}
}

21 changes: 19 additions & 2 deletions lib/PdoOneCli.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php /** @noinspection PhpUnused */

/** @noinspection DuplicatedCode */


namespace eftec;

Expand Down Expand Up @@ -381,13 +381,30 @@ protected function getFiles(string $path, string $extension): array
$scanned2 = [];
foreach ($scanned_directory as $k) {
$fullname = pathinfo($k)['extension'] ?? '';
if (str_ends_with($fullname, $extension)) {
if ($this->str_ends_with($fullname, $extension)) {
$scanned2[$k] = $k;
}
}
return $scanned2;
}

/**
* for PHP <8.0 compatibility
* @param string $haystack
* @param string $needle
* @return bool
*
*/
protected function str_ends_with(string $haystack, string $needle): bool
{
$needle_len = strlen($needle);
$haystack_len = strlen($haystack);
if($haystack_len<$needle_len) {
return false;
}
return ($needle_len === 0 || 0 === substr_compare($haystack, $needle, - $needle_len));
}

protected function showLogo(): void
{
$v = PdoOne::VERSION;
Expand Down
273 changes: 135 additions & 138 deletions tests/PdoOneCli_Test.php
Original file line number Diff line number Diff line change
@@ -1,138 +1,135 @@
<?php

namespace eftec\tests;

use eftec\CliOne\CliOne;
use eftec\PdoOneCli;
use Exception;
use PHPUnit\Framework\TestCase;

include_once __DIR__ . '/../lib/PdoOneCli.php';

class PdoOneCli_Test extends TestCase
{
public function setUp():void {

chdir(__DIR__);
}
/**
* @return void
* @throws Exception
*/
public function test1(): void
{


CliOne::testUserInput(null);
CliOne::testArguments(['program.php',
'export',
'--databasetype',
'mysql',
'--server',
'127.0.0.1',
'--user',
'root',
'--password',
'abc.123',
'--database',
'sakila',
'--input',
'actor',
'--output',
'csv']);
$p = new PdoOneCli();
$p->getCli()->echo = false;
$p->cliEngine();
$this->assertStringContainsString('1,"PENELOPE"', $p->getCli()->getMemory(true));
// second test
CliOne::testArguments(['program.php',
'export',
'--databasetype',
'mysql',
'--server',
'127.0.0.1',
'--user',
'root',
'--password',
'abc.123',
'--database',
'sakila',
'--input',
'actor',
'--output',
'json']);
$p = new PdoOneCli();
$p->getCli()->echo = false;
$p->cliEngine();
$this->assertStringContainsString('[{"actor_id":1,"first_name":"PENELOPE"', $p->getCli()->getMemory(true));
}

/**
* @throws Exception
*/


/**
* @return void
* @throws Exception
*/
public function testinteractive1(): void
{
chdir(__DIR__);
CliOne::testUserInput(['mysql', '127.0.0.1', 'root', 'abc.123', 'sakila', 'yes', 'tmp/c1']);
CliOne::testArguments(['program.php',
'-i']);
$p = new PdoOneCli();
$p->getCli()->echo = true;
$p->cliEngine();
$this->assertEquals([
'databasetype' => 'mysql',
'server' => '127.0.0.1',
'user' => 'root',
'password' => 'abc.123',
'database' => 'sakila',
'input' => '',
'output' => '',
'namespace' => '',
'tablexclass' => array(),
'conversion' => array(),
'extracolumn' => array(),
'removecolumn' => array(),
'columnsTable' => array(),
'help' => false,
'classdirectory' => null,
'classnamespace' => null,
], $p->getCli()->readData('tmp/c1')[1]);
}

/**
* @throws Exception
*/
public function testinteractive2(): void
{
chdir(__DIR__);
CliOne::testUserInput(['mysql', '127.0.0.1', 'root', 'abc.123', 'sakila', 'yes', 'tmp/c1']);
CliOne::testArguments(['program.php','-cli']);
$p = new PdoOneCli();
$p->getCli()->echo = true;
$p->cliEngine();
$this->assertEquals([
'databasetype' => 'mysql',
'server' => '127.0.0.1',
'user' => 'root',
'password' => 'abc.123',
'database' => 'sakila',
'input' => '',
'output' => '',
'namespace' => '',
'tablexclass' => array(),
'conversion' => array(),
'extracolumn' => array(),
'removecolumn' => array(),
'columnsTable' => array(),
'help' => false,
'classdirectory' => null,
'classnamespace' => null,
], $p->getCli()->readData('tmp/c1')[1]);
}
}
<?php

namespace eftec\tests;

use eftec\CliOne\CliOne;
use eftec\PdoOneCli;
use Exception;
use PHPUnit\Framework\TestCase;

include_once __DIR__ . '/../lib/PdoOneCli.php';

class PdoOneCli_Test extends TestCase
{
public function setUp():void {

chdir(__DIR__);
}
/**
* @return void
* @throws Exception
*/
public function test1(): void
{
CliOne::testUserInput(null);
CliOne::testArguments(['program.php',
'export',
'--databasetype',
'mysql',
'--server',
'127.0.0.1',
'--user',
'root',
'--password',
'abc.123',
'--database',
'sakila',
'--input',
'actor',
'--output',
'csv']);
$p = new PdoOneCli();
$p->getCli()->echo = false;
$this->assertStringContainsString('1,"PENELOPE"', $p->getCli()->getMemory(true));
// second test
CliOne::testArguments(['program.php',
'export',
'--databasetype',
'mysql',
'--server',
'127.0.0.1',
'--user',
'root',
'--password',
'abc.123',
'--database',
'sakila',
'--input',
'actor',
'--output',
'json']);
$p = new PdoOneCli();
$p->getCli()->echo = false;
$p->cliEngine();
$this->assertStringContainsString('[{"actor_id":1,"first_name":"PENELOPE"', $p->getCli()->getMemory(true));
}

/**
* @throws Exception
*/


/**
* @return void
* @throws Exception
*/
public function testinteractive1(): void
{
chdir(__DIR__);
CliOne::testUserInput(['mysql', '127.0.0.1', 'root', 'abc.123', 'sakila', 'yes', 'tmp/c1']);
CliOne::testArguments(['program.php',
'-i']);
$p = new PdoOneCli();
$p->getCli()->echo = true;

$this->assertEquals([
'databasetype' => 'mysql',
'server' => '127.0.0.1',
'user' => 'root',
'password' => 'abc.123',
'database' => 'sakila',
'input' => '',
'output' => '',
'namespace' => '',
'tablexclass' => array(),
'conversion' => array(),
'extracolumn' => array(),
'removecolumn' => array(),
'columnsTable' => array(),
'help' => false,
'classdirectory' => null,
'classnamespace' => null,
], $p->getCli()->readData('tmp/c1')[1]);
}

/**
* @throws Exception
*/
public function testinteractive2(): void
{
chdir(__DIR__);
CliOne::testUserInput(['mysql', '127.0.0.1', 'root', 'abc.123', 'sakila', 'yes', 'tmp/c1']);
CliOne::testArguments(['program.php','-cli']);
$p = new PdoOneCli();
$p->getCli()->echo = true;
$p->cliEngine();
$this->assertEquals([
'databasetype' => 'mysql',
'server' => '127.0.0.1',
'user' => 'root',
'password' => 'abc.123',
'database' => 'sakila',
'input' => '',
'output' => '',
'namespace' => '',
'tablexclass' => array(),
'conversion' => array(),
'extracolumn' => array(),
'removecolumn' => array(),
'columnsTable' => array(),
'help' => false,
'classdirectory' => null,
'classnamespace' => null,
], $p->getCli()->readData('tmp/c1')[1]);
}
}

0 comments on commit 8ca8ead

Please sign in to comment.