Skip to content

Commit

Permalink
#8 added getStatusData method
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasFranek committed Jul 7, 2018
1 parent 0532443 commit c72fd76
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 1 deletion.
88 changes: 88 additions & 0 deletions src/Models/StatusData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Webuntis\Models;

use Webuntis\Models\AbstractModel;
use Webuntis\Models\Interfaces\CachableModelInterface;
use Webuntis\Models\Interfaces\AdministrativeModelInterface;
use JMS\Serializer\Annotation\SerializedName;

class StatusData extends AbstractModel implements CachableModelInterface, AdministrativeModelInterface
{
const CACHE_LIFE_TIME = 0;
const METHOD = "getStatusData";

/**
* @var array
* @SerializedName("lessonTypes")
*/
private $lessonTypes;

/**
* @var array
*/
private $codes;

/**
* Getter for lessonTypes
*
* @return array
*/
public function getLessonTypes() : array
{
return $this->lessonTypes;
}

/**
* Setter for lessonTypes
*
* @param array $lessonTypes
*
* @return StatusData
*/
public function setLessonTypes(array $lessonTypes) : self
{
$this->lessonTypes = $lessonTypes;

return $this;
}

/**
* Getter for codes
*
* @return array
*/
public function getCodes() : array
{
return $this->codes;
}

/**
* Setter for codes
*
* @param array $codes
*
* @return StatusData
*/
public function setCodes(array $codes) : self
{
$this->codes = $codes;

return $this;
}

/**
* sets an given field
*
* @param mixed $field
* @param mixed $value
*
* @return StatusData
*/
public function set($field, $value) : self
{
$this->$field = $value;

return $this;
}
}
23 changes: 23 additions & 0 deletions src/Repositories/StatusDataRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
declare(strict_types=1);

namespace Webuntis\Repositories;
use Webuntis\Models\Schoolyears;
use Webuntis\Models\CurrentSchoolyear;
use Webuntis\Handler\ExecutionHandler;

/**
* StatusDataRepository
* @author Tobias Franek <[email protected]>
* @license MIT
*/
class StatusDataRepository extends Repository {

/**
* {@inheritdoc}
*/
public function parse(array $result) : array
{
return [new $this->model($result)];
}
}
11 changes: 11 additions & 0 deletions src/Resources/config/StatusData.webuntis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Webuntis\Models\StatusData:
repositoryClass: Webuntis\Repositories\StatusDataRepository
fields:
lessonTypes:
type: array
api:
name: lstypes
codes:
type: array
api:
name: codes
4 changes: 3 additions & 1 deletion tests/Configuration/YAMLConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function testLoad() : void
'Substitutions' => 'Webuntis\Models\Substitutions',
'Teachers' => 'Webuntis\Models\Teachers',
'ClassRegEvents' => 'Webuntis\Models\ClassRegEvents',
'StatusData' => 'Webuntis\Models\StatusData'
];
$expectedRepositories = [
'Default' => 'Webuntis\Repositories\Repository',
Expand All @@ -40,7 +41,8 @@ public function testLoad() : void
'Period' => 'Webuntis\Repositories\PeriodRepository',
'Schoolyears' => 'Webuntis\Repositories\SchoolyearsRepository',
'Substitutions' => 'Webuntis\Repositories\SubstitutionsRepository',
'ClassRegEvents' => 'Webuntis\Repositories\ClassRegEventsRepository'
'ClassRegEvents' => 'Webuntis\Repositories\ClassRegEventsRepository',
'StatusData' => 'Webuntis\Repositories\StatusDataRepository'
];
$gottenModels = $yamlConfiguration->getModels();

Expand Down
50 changes: 50 additions & 0 deletions tests/Models/StatusDataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);

namespace Webuntis\Tests\Models;

use PHPUnit\Framework\TestCase;
use Webuntis\Models\StatusData;

/**
* StatusDataTest
* @author Tobias Franek <[email protected]>
* @license MIT
*/
final class StatusDataTest extends TestCase
{
public function testCreate() : void
{
$data = [
'id' => 1,
'lstypes' => [
'test' => 'test'
],
'codes' => [
'test' => 'test'
]
];

$classes = new StatusData($data);

$this->assertEquals(1, $classes->getId());
$this->assertEquals([
'test' => 'test'
], $classes->getLessonTypes());
$this->assertEquals([
'test' => 'test'
], $classes->getCodes());

$expected = [
'id' => 1,
'lessonTypes' => [
'test' => 'test'
],
'codes' => [
'test' => 'test'
]
];

$this->assertEquals($expected, $classes->serialize());
}
}

0 comments on commit c72fd76

Please sign in to comment.