[TYPO3-english] Typo3 CLI and PHPUnit
Knut Behrends
knb at gfz-potsdam.de
Wed Jan 22 10:00:49 CET 2014
Here is some code to get you started.
If your extension is called myext, put this class into a directory
called myext/test
These tests are checking the mysql connectivity via dbal. In the
username, password, connectionstring fields/param you should put your
oen values.
<?php
/**
* Testsuite for the myext typo3-extension
* Testing the availability of an external db, is connection properly
configured (in localconf.php),
* Testing if "native" connectivity is possible at all
* @author Knut Behrends
* @package TYPO3
* @subpackage tx_icdpdb
*
* $Id: class.tx_icdpdb_dbal_mysql_native_default_Test.php 2106
2013-09-05 14:20:33Z knb $
* $HeadURL:
http://svn....typo3conf/ext/myext/tests/class.tx_icdpdb_dbal_mysql_native_default_Test.php
$
*/
class tx_icdpdb_dbal_mysql_native_default_Test extends
PHPUnit_Framework_TestCase {
private $config;
private $conn;
private $defaultconnprofile;
private $connprofilestr;
private $isconnected;
public function setUp() {
//$this->database = t3lib_div::makeInstance('tx_icdpdb_sv_mysql');
$this->connprofilestr = "_DEFAULT";
$this->defaultconnprofile =
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg'][$this->connprofilestr];
$this->config =
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg'][$this->connprofilestr]['config'];
$this->conn = t3lib_div::makeInstance('t3lib_DB');
$this->conn->debug = true;
$this->conn->connectDB();
$this->isconnected = $this->conn->handler_init($this->connprofilestr);
// this->fixture = new ...;
}
/**
* the config value for the default db is there
* @test
*/
public function default_handlerCfg_type_exists_as_array_key() {
$this->assertArrayHasKey('type' , $this->defaultconnprofile);
}
/**
* the config value for the default db is there
* @test
*/
public function default_handlerCfg_type_is_native() {
$this->assertEquals($this->defaultconnprofile['type'], "native");
$type =
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg'][$this->connprofilestr]['type'];
$this->assertEquals($type, "native", "type: $type");
}
/**
* the config value for the default db is there
* @test
*/
public function
default_handlerCfg_has_query_cache_so_constructor_was_called() {
$this->assertInstanceOf('t3lib_sqlparser', $this->conn->SQLparser,
"assert that database access class has an SQLparser, so constructor was
called.");
//$this->assertInstanceOf('t3lib_cache_Manager',
$this->conn->queryCache, "assert that database access class has a query
cache, so constructor was called.");
}
/**
*
* @test
*
*/
public function can_instantiate_dbal_with_polymorphism() {
$this->assertInstanceOf("ux_t3lib_DB", $this->conn, "is of class
't3lib_DB'");
$this->assertInstanceOf("ux_t3lib_DB", $this->conn, "is of class
'ux_t3lib_DB' (polymorphism!)");
}
/**
*
* @test
*($host = TYPO3_db_host, $user = TYPO3_db_username, $password =
TYPO3_db_password, $db = TYPO3_db
*/
public function default_lastHandlerKey_is_set_on_instance_creation() {
$this->assertAttributeInternalType ("string", "lastHandlerKey",
t3lib_div::makeInstance('ux_t3lib_DB'), "is a string");
}
/**
*
* @test
*($host = TYPO3_db_host, $user = TYPO3_db_username, $password =
TYPO3_db_password, $db = TYPO3_db
*/
public function default_handlerCfg_native_linkproperty_is_resource() {
$actualResult = is_resource($this->conn->link);
$c = get_class($this->conn);
$this->assertTrue($actualResult, "\$this->conn->link is a resource ()
class: $c" );
}
/**
*
* @test
*($host = TYPO3_db_host, $user = TYPO3_db_username, $password =
TYPO3_db_password, $db = TYPO3_db
*/
public function default_handlerCfg_runningNative_returns_true() {
//$this->conn->connectDB($this->host,$this->username,$this->password,$this->database);
//$actualResult = $this->conn->handler_init("_DEFAULT");
$actualResult = (string)
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['dbal']['handlerCfg'][$this->connprofilestr]['type']
;
$this->assertTrue($actualResult === 'native',
$this->conn->lastHandlerKey . " runningNative(): $actualResult");
}
/**
*
* @test
*($host = TYPO3_db_host, $user = TYPO3_db_username, $password =
TYPO3_db_password, $db = TYPO3_db
*/
public function default_admin_get_dbs_returns_data() {
$actualResult = $this->conn->admin_get_dbs();
$this->assertTrue(is_array($actualResult), "admin_get_dbs() returns
array, values:" . implode(",", array_values($actualResult)));
}
/**
* (non-PHPdoc)
*
* @see PHPUnit_Framework_TestCase::tearDown()
*/
public function tearDown() {
// unset($this->fixture);
//$this->database->unlinkTempFiles();
//var $t;
//$t = new tx_icdpdb_sv_mysql();
}
}
?>
On 2014-01-21 21:44, John Foushee wrote:
> I'm trying to set up PHPUnit for Typo3. I've installed the PHPUnit
> extension as well as the PHPUnit CLI extension. I'd like the PHPUnit
> tests to be run on a separate test database. What's the best way of
> making Typo3's CLI bootstrap run with a different db config?
>
> As of now, when I run the PHPUnit command
>
> ==
> /typo3/cli_dispatch.phpsh phpunit
> ./typo3conf/ext/phpunit/TestExtensions/aaa
> ==
>
> I see the following output
>
> ----
> PHPUnit 3.7.22 by Sebastian Bergmann.
>
> FF
>
> Time: 0 seconds, Memory: 16.00Mb
>
> There were 2 failures:
>
> 1) Warning
> No tests found in class "Tx_Aaa_Tests_OneTest".
>
> /var/www/typo3conf/ext/phpunit/Classes/TestRunner/CliTestRunner.php:43
> /var/www/typo3conf/ext/phpunit/Scripts/ManualCliTestRunner.php:27
>
> 2) Warning
> No tests found in class "Tx_Aaa_Tests_Fixtures_AnotherTest".
>
> /var/www/typo3conf/ext/phpunit/Classes/TestRunner/CliTestRunner.php:43
> /var/www/typo3conf/ext/phpunit/Scripts/ManualCliTestRunner.php:27
>
> FAILURES!
> Tests: 2, Assertions: 0, Failures: 2.
> ----
>
> I'm running on a CentOS 6.4 LAMP stack with Typo3 v6.1
>
> I'm quite new to Typo3 so any advice would be appreciated.
> _______________________________________________
> TYPO3-english mailing list
> TYPO3-english at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-english
--
____________________________________________________________________________
Knut Behrends Phone: +49 (0) 331 288 1688
Helmholtz-Zentrum Potsdam Fax : +49 (0) 331 288 1088
Deutsches GeoForschungsZentrum - GFZ Email: knb at gfz-potsdam.de
Telegrafenberg A 69 URL : www.icdp-online.org
Potsdam 14473 KeyID: 0xF22CACEF (PGP Public Key)
____________________________________________________________________________
More information about the TYPO3-english
mailing list