source: src/webapp/webservice/tests/Nmea0183RmcTest.php@ ce301d3

debian/bullseye
Last change on this file since ce301d3 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: 6.0 KB
RevLine 
[86442cb]1<?php
2/*
[c0e66e6]3 Copyright (C) 2017 - 2018 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
[86442cb]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;
[86442cb]22
23/**
24 * @brief Covers Nmea0183Rmc.php
25 */
[c0e66e6]26final class Nmea0183RmcTest extends TestCase
[86442cb]27{
28 /**
29 * @dataProvider rmcProvider
30 */
31 public function testRmc($sentence, $talker, $type, $dateTimeUtc, $status, $latitude, $latitudeDirection,
32 $longitude, $longitudeDirection, $speedOverGround, $courseOverGround,
33 $magneticalDeclination, $magneticalDeclinationDirection, $signalIntegrity,
34 $checksum, $valid)
35 {
36 $format = 'Y-m-d H:i:s';
37
38 $parser = new GnuBoat\Nmea\Parser();
39 $sentence = $parser->parseSentence($sentence, "0183");
40 $this->assertInstanceOf(GnuBoat\Nmea\Nmea0183\Nmea0183Rmc::class, $sentence);
41 $this->assertEquals($talker, $sentence->talker());
42 $this->assertEquals($type, $sentence->type());
43 $dateTime = $sentence->dateTime();
44 if($dateTimeUtc == null)
45 $this->assertNull($dateTime);
46 else{
47 $this->assertInstanceOf(DateTime::class, $dateTime);
48 $this->assertEquals($dateTimeUtc->format($format), $dateTime->format($format));
49 }
50 $this->assertEquals($sentence->status(), $status);
[f29f4d3]51 $this->assertEquals($latitude, $sentence->latitude(), '', 0.0001);
52 $this->assertEquals($longitude, $sentence->longitude(), '', 0.0001);
[86442cb]53 $this->assertEquals($speedOverGround, $sentence->speedOverGround());
54 $this->assertEquals($courseOverGround, $sentence->courseOverGround());
55 $this->assertEquals($magneticalDeclination, $sentence->magneticDeclination());
56 $this->assertEquals($magneticalDeclinationDirection, $sentence->magneticDeclinationDirection());
57 $this->assertEquals($signalIntegrity, $sentence->signalIntegrity());
58 $this->assertEquals($checksum, $sentence->checksum());
59 $message = "";
60 $result = $sentence->valid($message);
61 $this->assertEquals($valid, $result, $message);
62 }
63
64 public function rmcProvider()
65 {
66 $format = 'Y-m-d H:i:s';
67 $formatMilli = 'Y-m-d H:i:s.u';
68
69 return [
70 "wrong_data_count" => [
71 '$GPRMC,162614,A,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*13',
[008bce9]72 "GP", "rmc", null,
[86442cb]73 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::V, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
74 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
75 0, 0, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
76 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::DataNotValid, 13, false
77 ],
78 "wrong_checksum" => [
79 '$GPRMC,162614,A,5230.5900,N,01322.3900,E,10.0,90.0,131006,1.2,E,A*22',
[008bce9]80 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
[f29f4d3]81 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 52.5098, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
82 13.3731, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
[86442cb]83 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
84 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 22, false
85 ],
[26f77a6]86 "position_conversion" => [
87 '$GPRMC,191410,A,4735.5634,N,00739.3538,E,0.0,0.0,181102,0.4,E,A*19',
88 "GP", "rmc", DateTime::createFromFormat($format, "2002-11-18 19:14:10", new DateTimeZone("UTC")),
89 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 47.5927, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
90 7.6558, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
91 0, 0, 0.4, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
92 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 19, true
93 ],
94 "position_conversion_lon" => [
95 '$GNRMC,133014,A,4825.64749998,N,01002.55130002,E,00.0,337.9,281017,,,A*51',
96 "GN", "rmc", DateTime::createFromFormat($format, "2017-10-28 13:30:14", new DateTimeZone("UTC")),
97 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 48.4274, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
98 10.0425, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
99 0, 337.9, 0, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::Invalid,
100 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 51, true
101 ],
[86442cb]102 "valid1" => [
[26f77a6]103 '$GPRMC,122548,A,4735.4480,N,01042.6240,E,10.0,115.6,131006,1.2,E,A*2D',
[f29f4d3]104 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 12:25:48", new DateTimeZone("UTC")),
105 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 47.5908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
106 10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
107 10, 115.6, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
[26f77a6]108 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '2d', true
[86442cb]109 ],
110 "valid2" => [
[26f77a6]111 '!GPRMC,162614,A,4735.4480,S,01042.6240,E,10.0,90,131006,,,A*72',
[008bce9]112 "GP", "rmc", DateTime::createFromFormat($format, "2006-10-13 16:26:14", new DateTimeZone("UTC")),
[f29f4d3]113 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, -47.5908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::South,
114 10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
115 10, 90, 0, false,
[26f77a6]116 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, '72', true
[86442cb]117 ],
118 "valid3" => [
[26f77a6]119 '$GNRMC,162614,A,7305.4480,N,01042.6240,W,10.0,90,131006,1.2,E,A*F',
[f29f4d3]120 "GN", "rmc", DateTime::createFromFormat($formatMilli, "2006-10-13 16:26:14.123", new DateTimeZone("UTC")),
[26f77a6]121 GnuBoat\Nmea\Nmea0183\Nmea0183RmcStatus::A, 73.0908, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::North,
[f29f4d3]122 -10.7104, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::West,
[86442cb]123 10, 90, 1.2, GnuBoat\Nmea\Nmea0183\Nmea0183Direction::East,
[26f77a6]124 GnuBoat\Nmea\Nmea0183\Nmea0183RmcSignal::AutonomousMode, 'f', true
[86442cb]125 ]
126 ];
127 }
128}
129
130?>
Note: See TracBrowser for help on using the repository browser.