mirror of
https://github.com/FriendsOfTYPO3/tea.git
synced 2024-12-22 23:06:11 +01:00
[FEATURE] Add examples for using the Testing Framework
This commit is contained in:
parent
12c69e81b0
commit
1c3031597b
3 changed files with 108 additions and 1 deletions
|
@ -3,6 +3,9 @@
|
|||
This TYPO3 extension is an example for writing unit tests for extbase
|
||||
extensions for TYPO3 CMS using PHPUnit.
|
||||
|
||||
The functional tests for the Repositories provide an example of creating
|
||||
records using the PHPUnit extension testing framework.
|
||||
|
||||
The functional test for the Utility/FileUtility class provides examples
|
||||
for working with [vfsStream](https://github.com/mikey179/vfsStream/).
|
||||
|
||||
|
|
102
Tests/Functional/Domain/Repository/TestimonialRepositoryTest.php
Normal file
102
Tests/Functional/Domain/Repository/TestimonialRepositoryTest.php
Normal file
|
@ -0,0 +1,102 @@
|
|||
<?php
|
||||
namespace OliverKlee\Tea\Tests\Functional\Utility;
|
||||
|
||||
/*
|
||||
* This file is part of the TYPO3 CMS project.
|
||||
*
|
||||
* It is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU General Public License, either version 2
|
||||
* of the License, or any later version.
|
||||
*
|
||||
* For the full copyright and license information, please read the
|
||||
* LICENSE.txt file that was distributed with this source code.
|
||||
*
|
||||
* The TYPO3 project - inspiring people to share!
|
||||
*/
|
||||
|
||||
use OliverKlee\Tea\Domain\Model\Testimonial;
|
||||
use OliverKlee\Tea\Domain\Repository\TestimonialRepository;
|
||||
use TYPO3\CMS\Core\Utility\GeneralUtility;
|
||||
use TYPO3\CMS\Extbase\Object\ObjectManager;
|
||||
|
||||
/**
|
||||
* Test case.
|
||||
*
|
||||
* @author Oliver Klee <typo3-coding@oliverklee.de>
|
||||
*/
|
||||
class TestimonialRepositoryTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
|
||||
/**
|
||||
* @var TestimonialRepository
|
||||
*/
|
||||
protected $subject = null;
|
||||
|
||||
/**
|
||||
* @var \Tx_Phpunit_Framework
|
||||
*/
|
||||
protected $testingFramework = null;
|
||||
|
||||
protected function setUp() {
|
||||
$this->testingFramework = new \Tx_Phpunit_Framework('tx_tea');
|
||||
|
||||
/** @var ObjectManager $objectManager */
|
||||
$objectManager = GeneralUtility::makeInstance(ObjectManager::class);
|
||||
// We are using the object manager instead of new so that the dependencies get injected.
|
||||
// In a unit test, we would inject the mocked dependencies instead.
|
||||
$this->subject = $objectManager->get(TestimonialRepository::class);
|
||||
}
|
||||
|
||||
protected function tearDown() {
|
||||
$this->testingFramework->cleanUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function findAllForNoRecordsReturnsEmptyContainer() {
|
||||
$container = $this->subject->findAll();
|
||||
|
||||
self::assertSame(
|
||||
0,
|
||||
$container->count()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function findAllWithOneRecordFindsThisRecord() {
|
||||
$uid = $this->testingFramework->createRecord('tx_tea_domain_model_testimonial');
|
||||
|
||||
$container = $this->subject->findAll();
|
||||
/** @var Testimonial $first */
|
||||
$first = $container->getFirst();
|
||||
|
||||
self::assertSame(
|
||||
1,
|
||||
$container->count()
|
||||
);
|
||||
self::assertSame(
|
||||
$uid,
|
||||
$first->getUid()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function findByUidForExistingRecordReturnsModelWithData() {
|
||||
$text = 'A very good Early Grey!';
|
||||
$uid = $this->testingFramework->createRecord(
|
||||
'tx_tea_domain_model_testimonial', array('text' => $text)
|
||||
);
|
||||
|
||||
/** @var Testimonial $model */
|
||||
$model = $this->subject->findByUid($uid);
|
||||
|
||||
self::assertNotNull($model);
|
||||
self::assertSame(
|
||||
$text,
|
||||
$model->getText()
|
||||
);
|
||||
}
|
||||
}
|
|
@ -133,6 +133,7 @@ CREATE TABLE tx_tea_domain_model_testimonial (
|
|||
crdate int(11) unsigned DEFAULT '0' NOT NULL,
|
||||
cruser_id int(11) unsigned DEFAULT '0' NOT NULL,
|
||||
deleted tinyint(4) unsigned DEFAULT '0' NOT NULL,
|
||||
is_dummy_record tinyint(1) unsigned DEFAULT '0' NOT NULL,
|
||||
hidden tinyint(4) unsigned DEFAULT '0' NOT NULL,
|
||||
starttime int(11) unsigned DEFAULT '0' NOT NULL,
|
||||
endtime int(11) unsigned DEFAULT '0' NOT NULL,
|
||||
|
@ -155,7 +156,8 @@ CREATE TABLE tx_tea_domain_model_testimonial (
|
|||
PRIMARY KEY (uid),
|
||||
KEY parent (pid),
|
||||
KEY t3ver_oid (t3ver_oid,t3ver_wsid),
|
||||
KEY language (l10n_parent,sys_language_uid)
|
||||
KEY language (l10n_parent,sys_language_uid),
|
||||
KEY phpunit_dummy (is_dummy_record)
|
||||
);
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in a new issue