Skip to content

Commit

Permalink
#11 some unit tests fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
digedag committed May 4, 2020
1 parent 0a0fafd commit f39e67b
Show file tree
Hide file tree
Showing 18 changed files with 149 additions and 69 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### travis builds
/.Build
/composer.lock
/var

### eclipse files
.settings
.buildpath

3 changes: 2 additions & 1 deletion Classes/Action/CoachStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Sys25\RnBase\Frontend\Controller\AbstractAction;
use Sys25\RnBase\Frontend\Request\RequestInterface;
use System25\T3sports\Service\StatsServiceRegistry;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -69,7 +70,7 @@ protected function handleRequest(RequestInterface $request)

private function findData($parameters, $configurations, $viewData, $type)
{
$srv = \tx_t3sportstats_util_ServiceRegistry::getStatisticService();
$srv = (new StatsServiceRegistry())->getStatisticService();
$confId = $this->getConfId().$type.'.';
$filter = \tx_rnbase_filter_BaseFilter::createFilter($parameters, $configurations, $viewData, $confId);

Expand Down
3 changes: 2 additions & 1 deletion Classes/Action/PlayerStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Sys25\RnBase\Frontend\Controller\AbstractAction;
use Sys25\RnBase\Frontend\Request\RequestInterface;
use System25\T3sports\Service\StatsServiceRegistry;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -66,7 +67,7 @@ protected function handleRequest(RequestInterface $request)

private function findData($parameters, $configurations, $viewData, $type)
{
$srv = \tx_t3sportstats_util_ServiceRegistry::getStatisticService();
$srv = (new StatsServiceRegistry())->getStatisticService();
$confId = $this->getConfId().$type.'.';
$filter = \tx_rnbase_filter_BaseFilter::createFilter($parameters, $configurations, $viewData, $confId);

Expand Down
3 changes: 2 additions & 1 deletion Classes/Action/RefereeStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Sys25\RnBase\Frontend\Controller\AbstractAction;
use Sys25\RnBase\Frontend\Request\RequestInterface;
use System25\T3sports\Service\StatsServiceRegistry;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -69,7 +70,7 @@ protected function handleRequest(RequestInterface $request)

private function findData($parameters, $configurations, $viewData, $type)
{
$srv = \tx_t3sportstats_util_ServiceRegistry::getStatisticService();
$srv = (new StatsServiceRegistry())->getStatisticService();
$confId = $this->getConfId().$type.'.';
$filter = \tx_rnbase_filter_BaseFilter::createFilter($parameters, $configurations, $viewData, $confId);

Expand Down
4 changes: 3 additions & 1 deletion Classes/Hooks/ClearStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace System25\T3sports\Hooks;

use System25\T3sports\Service\StatsServiceRegistry;

/***************************************************************
* Copyright notice
*
Expand Down Expand Up @@ -31,7 +33,7 @@ class ClearStats
{
public function clearStats4Comp($params, $parent)
{
$srv = \tx_t3sportstats_util_ServiceRegistry::getStatisticService();
$srv = (new StatsServiceRegistry())->getStatisticService();
/* @var $comp \tx_cfcleague_models_Competition */
$comp = \tx_rnbase::makeInstance('tx_cfcleague_models_Competition', $params['compUid']);
if ($comp && $comp->isValid()) {
Expand Down
3 changes: 2 additions & 1 deletion Classes/Hooks/Marker.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace System25\T3sports\Hooks;

use System25\T3sports\Marker\PlayerStatsMarker;
use System25\T3sports\Service\StatsServiceRegistry;

/***************************************************************
* Copyright notice
Expand Down Expand Up @@ -93,7 +94,7 @@ public function parseProfile($params, $parent)

private function findData($profile, $configurations, $confId, $type)
{
$srv = \tx_t3sportstats_util_ServiceRegistry::getStatisticService();
$srv = (new StatsServiceRegistry())->getStatisticService();
$confId = $confId.$type.'.';
$filter = \tx_rnbase_filter_BaseFilter::createFilter(
new \ArrayObject(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace System25\T3sports\Service;

/***************************************************************
* Copyright notice
*
* (c) 2010-2016 Rene Nitzsche ([email protected])
* (c) 2010-2020 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand All @@ -22,23 +25,19 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

tx_rnbase::load('tx_rnbase_util_Misc');

/**
* Zentrale Klasse für den Zugriff auf verschiedene Services.
*/
class tx_t3sportstats_util_ServiceRegistry
class StatsServiceRegistry
{
/**
* Liefert den Statistik-Service.
*
* @return tx_t3sportstats_srv_Statistics
* @return \tx_t3sportstats_srv_Statistics
*/
public static function getStatisticService()
public function getStatisticService()
{
return tx_rnbase_util_Misc::getService('t3sportstats', 'statistics');
return \tx_rnbase_util_Misc::getService('t3sportstats', 'statistics');
}
}
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3sportstats/util/class.tx_t3sportstats_util_ServiceRegistry.php']) {
include_once $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/t3sportstats/util/class.tx_t3sportstats_util_ServiceRegistry.php'];
}
8 changes: 4 additions & 4 deletions Classes/Utility/StatsConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,15 @@ private static function registerStatsSimple($type, $column, $types)
{
$column = strtolower($column);
if (!is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'])) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'] = array();
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'] = [];
}

if (!array_key_exists($column, $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'])) {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'][$column] = array(
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'][$column] = [
'types' => $types,
);
];
} else {
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'][$column] .= ','.$types;
$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3sportstats'][$type]['simpleStats'][$column]['types'] .= ','.$types;
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

namespace System25\T3sports\Tests\Service;

use System25\T3sports\Utility\StatsMatchNoteProvider;
use System25\T3sports\Tests\StatsFixtureUtil;
use System25\T3sports\Service\StatsServiceRegistry;

/***************************************************************
* Copyright notice
*
* (c) 2008-2010 Rene Nitzsche ([email protected])
* (c) 2008-2020 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand All @@ -25,21 +29,36 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

class tx_t3sportstats_tests_srvPlayerGoalStats_testcase extends tx_phpunit_testcase
class PlayerGoalStatsTest extends \tx_rnbase_tests_BaseTestCase
{
private $statsService;

public function setUp()
{
$this->statsService = new \tx_t3sportstats_srv_Statistics();
\System25\T3sports\Utility\StatsConfig::registerPlayerStatsSimple('goals', '10,11,12,13');
\System25\T3sports\Utility\StatsConfig::registerPlayerStatsSimple('assists', '31');
\System25\T3sports\Utility\StatsConfig::registerPlayerStatsSimple('goalshead', '11');
\System25\T3sports\Utility\StatsConfig::registerPlayerStatsSimple('goalspenalty', '12');
\System25\T3sports\Utility\StatsConfig::registerPlayerStatsSimple('goalsown', '30');
}

/**
* @group unit
*/
public function test_indexPlayerStatsHome()
{
$matchIdx = 0;
$matches = tx_t3sportstats_tests_Util::getMatches();

$matches = StatsFixtureUtil::getMatches();
$match = $matches[$matchIdx];
$srv = tx_t3sportstats_util_ServiceRegistry::getStatisticService();
$bagHash = array();
$bags = $srv->getPlayerBags($match, true);
$bagHash = [];

$bags = $this->statsService->getPlayerBags($match, true);
foreach ($bags as $bag) {
$bagHash[$bag->getParentUid()] = $bag;
}
$notes = tx_t3sportstats_tests_Util::getMatchNotes($matchIdx);
$notes = StatsFixtureUtil::getMatchNotes($matchIdx);

$mnProv = StatsMatchNoteProvider::createInstance($notes);

Expand All @@ -59,19 +78,21 @@ public function test_indexPlayerStatsHome()
$this->assertEquals(1, $bagHash[110]->getTypeValue('goalsjoker'), 'Goals joker are wrong');
}

/**
* @group unit
*/
public function test_indexPlayerStatsGuest()
{
$matchIdx = 0;
$matches = tx_t3sportstats_tests_Util::getMatches();
$matches = StatsFixtureUtil::getMatches();

$match = $matches[$matchIdx];
$srv = tx_t3sportstats_util_ServiceRegistry::getStatisticService();
$bagHash = array();
$bags = $srv->getPlayerBags($match, false);
$bagHash = [];
$bags = $this->statsService->getPlayerBags($match, false);
foreach ($bags as $bag) {
$bagHash[$bag->getParentUid()] = $bag;
}
$notes = tx_t3sportstats_tests_Util::getMatchNotes($matchIdx);
$notes = StatsFixtureUtil::getMatchNotes($matchIdx);

$mnProv = StatsMatchNoteProvider::createInstance($notes);

Expand All @@ -83,14 +104,14 @@ public function test_indexPlayerStatsGuest()

public function testGetInstance()
{
$this->assertTrue(is_object(tx_rnbase_util_Misc::getService('t3sportsPlayerStats', 'goals')), 'Service not registered.');
$this->assertTrue(is_object(\tx_rnbase_util_Misc::getService('t3sportsPlayerStats', 'goals')), 'Service not registered.');
}

/**
* @return tx_t3sportstats_srv_PlayerTimeStats
* @return \tx_t3sportstats_srv_PlayerGoalStats
*/
private static function getService()
{
return tx_rnbase::makeInstance('tx_t3sportstats_srv_PlayerGoalStats');
return \tx_rnbase::makeInstance('tx_t3sportstats_srv_PlayerGoalStats');
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<?php

namespace System25\T3sports\Tests;

/***************************************************************
* Copyright notice
*
* (c) 2008-2017 Rene Nitzsche ([email protected])
* (c) 2008-2020 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand All @@ -22,34 +25,37 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

require_once tx_rnbase_util_Extensions::extPath('rn_base').'class.tx_rnbase.php';

tx_rnbase::load('tx_rnbase_util_Spyc');

class tx_t3sportstats_tests_Util
class StatsFixtureUtil
{
public static function createCompetition($uid, $saison, $agegroup)
{
return new tx_cfcleague_models_Competition(array('uid' => $uid, 'saison' => $saison, 'agegroup' => $agegroup));
return new \tx_cfcleague_models_Competition(array('uid' => $uid, 'saison' => $saison, 'agegroup' => $agegroup));
}

public static function getMatches()
{
$data = tx_rnbase_util_Spyc::YAMLLoad(self::getFixturePath('statistics.yaml'));
$data = \tx_rnbase_util_Spyc::YAMLLoad(self::getFixturePath('statistics.yaml'));
$comps = self::makeInstances($data['league_1'], $data['league_1']['clazz']);

$teamData = $data['league_1']['teams'];
$teams = [];
foreach (self::makeInstances($teamData, $teamData['clazz']) as $team) {
$teams[$team->getUid()] = $team;
}
$data = $data['league_1']['matches'];
$matches = self::makeInstances($data, $data['clazz']);
foreach ($matches as $match) {
/* @var \tx_cfcleague_models_Match $match*/
$match->setCompetition($comps[0]);
$match->setHome($teams[$match->getProperty('home')]);
$match->setGuest($teams[$match->getProperty('guest')]);
}

return $matches;
}

public static function getMatchNotes($matchIdx)
{
$data = tx_rnbase_util_Spyc::YAMLLoad(self::getFixturePath('statistics.yaml'));
$data = \tx_rnbase_util_Spyc::YAMLLoad(self::getFixturePath('statistics.yaml'));
$data = $data['league_1']['matches'][$matchIdx]['matchnotes'];
$notes = self::makeInstances($data, $data['clazz']);

Expand All @@ -59,8 +65,7 @@ public static function getMatchNotes($matchIdx)
private static function makeInstances($yamlData, $clazzName)
{
// Sicherstellen, daß die Klasse geladen wurde
$ret = array();
tx_rnbase::load($clazzName);
$ret = [];
foreach ($yamlData as $key => $arr) {
if (isset($arr['record']) && is_array($arr['record'])) {
$ret[$key] = new $clazzName($arr['record']);
Expand All @@ -72,6 +77,6 @@ private static function makeInstances($yamlData, $clazzName)

private static function getFixturePath($filename)
{
return tx_rnbase_util_Extensions::extPath('t3sportstats').'tests/fixtures/'.$filename;
return \tx_rnbase_util_Extensions::extPath('t3sportstats').'Tests/fixtures/'.$filename;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<?php

namespace System25\T3sports\Tests\Utility;

use System25\T3sports\Utility\StatsMatchNoteProvider;
use System25\T3sports\Tests\StatsFixtureUtil;

/***************************************************************
* Copyright notice
*
* (c) 2008-2010 Rene Nitzsche ([email protected])
* (c) 2008-2020 Rene Nitzsche ([email protected])
* All rights reserved
*
* This script is part of the TYPO3 project. The TYPO3 project is
Expand All @@ -25,12 +28,15 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/

class tx_t3sportstats_tests_utilMatchNoteProvider_testcase extends tx_phpunit_testcase
class tx_t3sportstats_tests_utilMatchNoteProvider_testcase extends \tx_rnbase_tests_BaseTestCase
{
/**
* @group unit
*/
public function test_getMatchNotes4Profile()
{
$matchIdx = 0;
$notes = tx_t3sportstats_tests_Util::getMatchNotes($matchIdx);
$notes = StatsFixtureUtil::getMatchNotes($matchIdx);
$mnProv = StatsMatchNoteProvider::createInstance($notes);
$notes = $mnProv->getMatchNotes4Profile(100);
$this->assertEquals(3, count($notes), 'Number of notes for player is wrong');
Expand Down
Loading

0 comments on commit f39e67b

Please sign in to comment.