Ignore:
Timestamp:
Aug 29, 2017, 6:19:00 PM (9 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
Branches:
0.5, debian/bullseye, debian/jessie, master
Children:
89c510f
Parents:
fc63b30
Message:

First more or less working version of visualising logfiles on the map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/webapp/webservice/tests/NmeaTest.php

    rfc63b30 r008bce9  
    2020// declare(Strict_types=1);
    2121
    22 /**
    23   * @brief Covers Parser.php
    24   */
    25 final class NmeaTest extends PHPUnit_Framework_TestCase
     22namespace GnuBoat\Nmea
    2623{
     24
    2725        /**
    28           * @dataProvider formatsProvider
    29           */
    30         public function testFormats($format)
     26        * @brief Covers Parser.php
     27        */
     28        final class NmeaTest extends \PHPUnit_Framework_TestCase
    3129        {
    32                 $parser = new GnuBoat\Nmea\Parser(0);
    33                 $formats = $parser->formatsSupported();
    34                 $this->assertInternalType('array', $formats);
    35                 $this->assertContains($format, $formats);
    36         }
    37        
    38         public function formatsProvider()
    39         {
    40                 return [["0183"]];
     30                /**
     31                * @dataProvider formatsProvider
     32                */
     33                public function testFormats($format)
     34                {
     35                        $parser = new Parser(0);
     36                        $formats = $parser->formatsSupported();
     37                        $this->assertInternalType('array', $formats);
     38                        $this->assertContains($format, $formats);
     39                }
     40               
     41                public function formatsProvider()
     42                {
     43                        return [["0183"]];
     44                }
     45
     46                /**
     47                * @dataProvider nmeaSentenceProvider
     48                */
     49                public function testNmeaSentence($format, $sentence, $classType, $valid)
     50                {
     51                        $parser = new Parser(0);
     52                        $sentence = $parser->parseSentence($sentence, $format);
     53                        if($classType == null)
     54                                $this->assertNull($sentence);
     55                        else{
     56                                $this->assertInstanceOf($classType, $sentence);
     57                                $message = "";
     58                                $result = $sentence->valid($message);
     59                                $this->assertEquals($valid, $result, $message);
     60                        }
     61                }
     62               
     63                public function nmeaSentenceProvider()
     64                {
     65                        return [
     66                                "empty" => ['0183', '', null, false],
     67                                "unsupported_format" => ['abc', '', null, false],
     68                                "rmc0183" => ['0183', '$GNRMC,173658,A,0047.589,N,00010.713,E,01.1,147.4,260817,,,A*5F', Nmea0183\Nmea0183Rmc::class, true],
     69                                "dpt0183" => ['0183', '$SDDPT,00.71,00.00*51', Nmea0183\Nmea0183Dpt::class, true],
     70                                "mtw0183" => ['0183', '$YXMTW,26.3,C*15', Nmea0183\Nmea0183Mtw::class, true],
     71                        ];
     72                }
     73               
     74                /**
     75                * @dataProvider nmeaFileProvider
     76                */
     77                public function testNmeaFile($file, $format, $count)
     78                {
     79                        $parser = new Parser(0);
     80                        $sentences = $parser->parseFile($file, $format);
     81                        $this->assertInternalType('array', $sentences);
     82                        $this->assertCount($count, $sentences);
     83                        foreach($sentences as $sentence){
     84                                $this->assertNotNull($sentence);
     85                                $this->assertInstanceOf(NmeaSentence::class, $sentence);
     86                                $this->assertEquals(true, $sentence->valid());
     87                        }
     88                }
     89               
     90                public function nmeaFileProvider()
     91                {
     92                        return [["webservice/tests/data/nmea0183.log", '0183', 2000]];
     93                }
    4194        }
    4295
    43         /**
    44          * @dataProvider nmeaSentenceProvider
    45          */
    46         public function testNmeaSentence($format, $sentence, $classType, $valid)
     96        function error_log($msg)
    4797        {
    48                 $parser = new GnuBoat\Nmea\Parser(0);
    49                 $sentence = $parser->parseSentence($sentence, $format);
    50                 if($classType == null)
    51                         $this->assertNull($sentence);
    52                 else{
    53                         $this->assertInstanceOf($classType, $sentence);
    54                         $message = "";
    55                         $result = $sentence->valid($message);
    56                         $this->assertEquals($valid, $result, $message);
    57                 }
     98                echo "ERR Nmea: ". $msg ."\n";
    5899        }
    59        
    60         public function nmeaSentenceProvider()
     100}
     101
     102namespace GnuBoat\Nmea\Nmea0183
     103{
     104        function error_log($msg)
    61105        {
    62                 return [
    63                         "empty" => ['0183', '', null, false],
    64                         "unsupported_format" => ['abc', '', null, false],
    65                         "rmc0183" => ['0183', '$GNRMC,173658,A,0047.589,N,00010.713,E,01.1,147.4,260817,,,A*5F', GnuBoat\Nmea\Nmea0183\Nmea0183Rmc::class, true],
    66                         "dpt0183" => ['0183', '$SDDPT,00.71,00.00*51', GnuBoat\Nmea\Nmea0183\Nmea0183Dpt::class, true],
    67                         "mtw0183" => ['0183', '$YXMTW,26.3,C*15', GnuBoat\Nmea\Nmea0183\Nmea0183Mtw::class, true],
    68                 ];
    69         }
    70        
    71         /**
    72          * @dataProvider nmeaFileProvider
    73          */
    74         public function testNmeaFile($file, $format, $count)
    75         {
    76                 $parser = new GnuBoat\Nmea\Parser(0);
    77                 $sentences = $parser->parseFile($file, $format);
    78                 $this->assertInternalType('array', $sentences);
    79                 $this->assertCount($count, $sentences);
    80                 foreach($sentences as $sentence){
    81                         $this->assertNotNull($sentence);
    82                         $this->assertInstanceOf(GnuBoat\Nmea\NmeaSentence::class, $sentence);
    83                         $this->assertEquals(true, $sentence->valid());
    84                 }
    85         }
    86        
    87         public function nmeaFileProvider()
    88         {
    89                 return [["webservice/tests/data/nmea0183.log", '0183', 2000]];
     106                echo "ERR Nmea0183: ". $msg ."\n";
    90107        }
    91108}
Note: See TracChangeset for help on using the changeset viewer.