dummyDbi = $this->createDbiDummy(); $this->dbi = $this->createDatabaseInterface($this->dummyDbi); DatabaseInterface::$instance = $this->dbi; } public function testError(): void { $this->dummyDbi->addResult('SELECT `COLUMN_NAME` AS `Field`, `COLUMN_TYPE` AS `Type`,' . ' `COLLATION_NAME` AS `Collation`,' . ' `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`,' . ' `COLUMN_DEFAULT` AS `Default`, `EXTRA` AS `Extra`, `PRIVILEGES` AS `Privileges`,' . ' `COLUMN_COMMENT` AS `Comment`' . ' FROM `information_schema`.`COLUMNS`' . ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'cvv\' AND `TABLE_NAME`' . ' COLLATE utf8_bin = \'enums\' AND `COLUMN_NAME` = \'set\' ORDER BY `ORDINAL_POSITION`', false); $this->dummyDbi->addResult('SHOW INDEXES FROM `cvv`.`enums`', false); $request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/') ->withParsedBody([ 'db' => 'cvv', 'table' => 'enums', 'column' => 'set', 'curr_value' => 'b&c', ]); Current::$database = 'cvv'; Current::$table = 'enums'; $responseRenderer = new ResponseRenderer(); $config = Config::getInstance(); $template = new Template($config); $relation = new Relation($this->dbi, $config); $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $sql = new Sql( $this->dbi, $relation, self::createStub(RelationCleanup::class), self::createStub(Transformations::class), $template, $bookmarkRepository, $config, $responseRenderer, ); $sqlController = new SetValuesController($responseRenderer, $template, $sql); $sqlController($request); self::assertFalse($responseRenderer->hasSuccessState(), 'expected the request to fail'); self::assertSame(['message' => 'Error in processing request'], $responseRenderer->getJSONResult()); } public function testSuccess(): void { $this->dummyDbi->addResult( 'SELECT `COLUMN_NAME` AS `Field`, `COLUMN_TYPE` AS `Type`, `COLLATION_NAME` AS `Collation`,' . ' `IS_NULLABLE` AS `Null`, `COLUMN_KEY` AS `Key`,' . ' `COLUMN_DEFAULT` AS `Default`, `EXTRA` AS `Extra`, `PRIVILEGES` AS `Privileges`,' . ' `COLUMN_COMMENT` AS `Comment`' . ' FROM `information_schema`.`COLUMNS`' . ' WHERE `TABLE_SCHEMA` COLLATE utf8_bin = \'cvv\' AND `TABLE_NAME` COLLATE utf8_bin = \'enums\'' . ' AND `COLUMN_NAME` = \'set\'' . ' ORDER BY `ORDINAL_POSITION`', [ [ 'set', 'set(\'\',\'a&b\',\'b&c\',\'vrai&\',\'\')', null, 'No', '', 'NULL', '', '', '', ], ], ['Field', 'Type', 'Collation', 'Null', 'Key', 'Default', 'Extra', 'Privileges', 'Comment'], ); $this->dummyDbi->addResult('SHOW INDEXES FROM `cvv`.`enums`', []); $request = ServerRequestFactory::create()->createServerRequest('POST', 'https://example.com/') ->withParsedBody([ 'db' => 'cvv', 'table' => 'enums', 'column' => 'set', 'curr_value' => 'b&c', ]); Current::$database = 'cvv'; Current::$table = 'enums'; $responseRenderer = new ResponseRenderer(); $config = Config::getInstance(); $template = new Template($config); $relation = new Relation($this->dbi, $config); $bookmarkRepository = new BookmarkRepository($this->dbi, $relation, $config); $sql = new Sql( $this->dbi, $relation, self::createStub(RelationCleanup::class), self::createStub(Transformations::class), $template, $bookmarkRepository, $config, $responseRenderer, ); $sqlController = new SetValuesController($responseRenderer, $template, $sql); $sqlController($request); self::assertTrue($responseRenderer->hasSuccessState(), 'expected the request not to fail'); self::assertSame( [ 'select' => '' . "\n", ], $responseRenderer->getJSONResult(), ); } }