source: src/webapp/webservice/tests/TrackItemTest.php@ 38a2121

debian/bullseye
Last change on this file since 38a2121 was c0e66e6, checked in by Joachim Langenbach <joachim.langenbach@…>, 8 years ago
  • Updated Tests to work with PHP 7
    • Added phing phar which works with PHP7 as a choice for the developer
    • Updated phpunit to 7.4.3 which works with PHP7 and removed old PHPUnit version
    • Updated test cases to work with PHPUnit 7.4.3
  • Property mode set to 100644
File size: 2.8 KB
RevLine 
[0662b2d]1<?php
2/*
[c0e66e6]3 Copyright (C) 2017 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
[0662b2d]4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19// enable in php 7
[c0e66e6]20declare(Strict_types=1);
21use PHPUnit\Framework\TestCase;
[0662b2d]22
23/**
24 * @brief Covers Service.php tests
25 */
[c0e66e6]26final class TrackItemTest extends \PHPUnit\Framework\TestCase
[0662b2d]27{
28 public function testConstructor()
29 {
30 $item = new GnuBoat\TrackItem();
31 $this->assertEquals(false, $item->isValid());
32 $this->assertNull($item->timestamp());
33 $this->assertNull($item->latitude());
34 $this->assertNull($item->longitude());
35
36 $item = new GnuBoat\TrackItem(1, 2, 3);
37 $this->assertEquals(true, $item->isValid());
38 $this->assertEquals(1, $item->timestamp());
39 $this->assertEquals(2, $item->latitude());
40 $this->assertEquals(3, $item->longitude());
41 }
42
43 /**
44 * @dataProvider propertiesProvider
45 */
46 public function testProperties($property, $value, $result)
47 {
48 $item = new GnuBoat\TrackItem();
49 $this->assertNull($item->getProperty($property), "Not set property ". $property ." is not null");
50 $this->assertEquals($result, $item->setProperty($property, $value), "Could not set property ". $property);
51 if($result)
52 $this->assertEquals($value, $item->getProperty($property));
53 else
54 $this->assertNull($item->getProperty($property));
55 }
56
57 public function propertiesProvider()
58 {
59 return [
60 ["asdasd", "bla", false],
61 ["TIME", time(), true],
62 ["time", time(), true],
63 ["time", "abc", false],
64 ["latitude", 12.1, true],
65 ["latitude", "abc", false],
66 ["speedthroughwater", 12.1, true],
67 ["speedthroughwater", "abc", false],
68 ["courseoverground", 12.1, true],
69 ["courseoverground", "abc", false],
70 ["waterdepth", 12.1, true],
71 ["waterdepth", "abc", false],
72 ["watertemperature", 12.1, true],
73 ["watertemperature", "abc", false],
74 ["gpsfix", 12.1, true],
75 ["gpsfix", "abc", false],
76 ];
77 }
78
79 public function testDateTime()
80 {
81 $item = new GnuBoat\TrackItem();
82 $this->assertNull($item->timestamp());
83 $dateTime = new DateTime();
84 $this->assertEquals(true, $item->setDateTime($dateTime));
85 $this->assertEquals($dateTime->getTimestamp(), $item->timestamp());
86 $this->assertEquals(true, $item->setDateTime(null));
87 $this->assertNull($item->timestamp());
88 }
89}
90
91?>
Note: See TracBrowser for help on using the repository browser.