Projekt

Obecné

Profil

« Předchozí | Další » 

Revize afb0cc02

Přidáno uživatelem Jakub Vašta před asi 4 roky(ů)

+ Re #8081
+ tests environmnet prepared
+ fast fix in build script

Zobrazit rozdíly:

.devcontainer/devcontainer.json
1
// For format details, see https://aka.ms/vscode-remote/devcontainer.json or this file's README at:
2
// https://github.com/microsoft/vscode-dev-containers/tree/v0.117.0/containers/docker-existing-docker-compose
3
// If you want to run as a non-root user in the container, see .devcontainer/docker-compose.yml.
4
{
5
	"name": "Existing Docker Compose (Extend)",
6

  
7
	// Update the 'dockerComposeFile' list if you have more compose files or use different names.
8
	// The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
9
	"dockerComposeFile": [
10
		"..\\docker-compose-dev.yml",
11
		"docker-compose.yml"
12
	],
13

  
14
	// The 'service' property is the name of the service for the container that VS Code should
15
	// use. Update this value and .devcontainer/docker-compose.yml to the real service name.
16
	"service": "php-fpm",
17

  
18
	// The optional 'workspaceFolder' property is the path VS Code should open by default when
19
	// connected. This is typically a file mount in .devcontainer/docker-compose.yml
20
	"workspaceFolder": "/workspace",
21

  
22
	// Set *default* container specific settings.json values on container create.
23
	"settings": { 
24
		"terminal.integrated.shell.linux": null
25
	},
26

  
27
	// Add the IDs of extensions you want installed when the container is created.
28
	"extensions": []
29

  
30
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
31
	// "forwardPorts": [],
32

  
33
	// Uncomment the next line if you want start specific services in your Docker Compose config.
34
	// "runServices": [],
35

  
36
	// Uncomment the next line if you want to keep your containers running after VS Code shuts down.
37
	// "shutdownAction": "none",
38

  
39
	// Uncomment the next line to run commands after the container is created - for example installing git.
40
	// "postCreateCommand": "apt-get update && apt-get install -y git",
41

  
42
	// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
43
	// "remoteUser": "vscode"
44
}
.devcontainer/docker-compose.yml
1
#-------------------------------------------------------------------------------------------------------------
2
# Copyright (c) Microsoft Corporation. All rights reserved.
3
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
4
#-------------------------------------------------------------------------------------------------------------
5

  
6
version: '3.2'
7
services:
8
  # Update this to the name of the service you want to work with in your docker-compose.yml file
9
  php-fpm:
10
    # If you want add a non-root user to your Dockerfile, you can use the "remoteUser"
11
    # property in devcontainer.json to cause VS Code its sub-processes (terminals, tasks, 
12
    # debugging) to execute as the user. Uncomment the next line if you want the entire 
13
    # container to run as this user instead. Note that, on Linux, you may need to 
14
    # ensure the UID and GID of the container user you create matches your local user. 
15
    # See https://aka.ms/vscode-remote/containers/non-root for details.
16
    #
17
    # user: vscode
18

  
19
    # Uncomment if you want to override the service's Dockerfile to one in the .devcontainer 
20
    # folder. Note that the path of the Dockerfile and context is relative to the *primary* 
21
    # docker-compose.yml file (the first in the devcontainer.json "dockerComposeFile"
22
    # array). The sample below assumes your primary file is in the root of your project.
23
    #
24
    # build:
25
    #   context: .
26
    #   dockerfile: .devcontainer/Dockerfile
27
    
28
    volumes:
29
      # Update this to wherever you want VS Code to mount the folder of your project
30
      - .:/workspace:cached
31

  
32
      # Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker-compose for details.
33
      # - /var/run/docker.sock:/var/run/docker.sock 
34

  
35
    # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust.
36
    # cap_add:
37
    #   - SYS_PTRACE
38
    # security_opt:
39
    #   - seccomp:unconfined
40

  
41
    # Overrides default command so things don't shut down after the process ends.
42
    command: /bin/sh -c "while sleep 1000; do :; done"
43
 
website/.env.test
1
APP_ENV=test
2
APP_SECRET=ca5751564bbb9a0d75d412e020790283
3
DATABASE_CONNECTION_STRING=mongodb://root:root@database
website/src/Controller/HeatmapController.php
51 51
    /**
52 52
     * @Route("heatmap/available/{date}", name="available")
53 53
     */
54
    public function availableDatasets(IOpenDataManager $manager, $date = '01012020') {
54
    public function availableDatasets(IOpenDataManager $manager, $date = '2020-01-01') {
55 55
        return $this->json($manager->getAvailableCollectionsByDay($date));
56 56
    }
57 57

  
website/src/Repository/OpenDataManager.php
16 16
    }
17 17

  
18 18
    public function getCollectionDataByName($name, $date, $hour) {
19
        if (null == $name || null == $date || null == $hour) {
20
            return [];
21
        }
22

  
19 23
        $valh = $hour < 10 ? '0'.$hour : $hour;
20 24
        $openData = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query(['date' => $date.'-'.$valh], []));
21 25

  
......
54 58
    }
55 59

  
56 60
    public function isCollectionAvailable($name, $date) {
61
        if (null == $name || null == $date) {
62
            return false;
63
        }
64

  
57 65
        $result = $this->manager->executeQuery('open-data-db.'.$name, new Query(['date' => $date], []));
58 66

  
59 67
        return !empty($result->toArray());
......
90 98
    }
91 99

  
92 100
    public function getMaxCollectionNumberAtDay($name, $date) {
101
        if (null == $name || null == $date) {
102
            return 0;
103
        }
104

  
93 105
        $max = $this->manager->executeQuery('open-data-db.'.$name.$date, new Query([], ['sort' => ['number' => -1], 'limit' => 1]));
94 106

  
95 107
        $max->setTypeMap([
......
100 112

  
101 113
        $result = $max->toArray();
102 114

  
103
        return empty($result) ? 1 : $result[0]['number'];
115
        return empty($result) ? 0 : $result[0]['number'];
104 116
    }
105 117

  
106 118
    public function getDataSourcePositions($name = 'NONE') {
119
        if (null == $name) {
120
            return [];
121
        }
122

  
107 123
        $positions = $this->manager->executeQuery('open-data-db.'.$name.'DEVICES', new Query([], []));
108 124

  
109 125
        $positions->setTypeMap([
website/tests/Controller/HeatmapControllerTest.php
6 6

  
7 7
class HatmapControllerTest extends WebTestCase {
8 8

  
9
    public function testMainPage() {
9
    public function testPageLoad() {
10 10
        $client = static::createClient();
11 11
        $client->request('GET', '/heatmap');
12
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
12
        $this->assertTrue($client->getResponse()->isSuccessful());
13 13
    }
14

  
15
    public function testPageLoadWithData() {
16
        $client = static::createClient();
17
        $client->request('GET', '/heatmap?data_set[date]=2019-04-11&data_set[time]=12&data_set[type]=JIS');
18
        $this->assertTrue($client->getResponse()->isSuccessful());
19
    }
20

  
21
    public function testPageLoadWithInvalidData() {
22
        $client = static::createClient();
23
        $client->request('GET', '/heatmap?data_set[date]=2019-04-11&data_set[time]=12&data_set[type]=NIC');
24
        $this->assertTrue($client->getResponse()->isSuccessful());
25

  
26
        $client->request('GET', '/heatmap?data_set[date]=2019-04-11&data_set[time]=25&data_set[type]=KOLOBEZKY');
27
        $this->assertTrue($client->getResponse()->isSuccessful());
28

  
29
        $client->request('GET', '/heatmap?data_set[date]=11-04-2019&data_set[time]=12&data_set[type]=KOLOBEZKY');
30
        $this->assertTrue($client->getResponse()->isSuccessful());
31
    }
32

  
33
    public function testFormSubmit() {
34
        $client = static::createClient();
35
        $client->request('GET', '/heatmap');
36

  
37
        $crawler = $client->submitForm('Potvrdit výběr');
38
        $this->assertTrue($client->getResponse()->isSuccessful());
39

  
40
        $crawler = $client->submitForm('Potvrdit výběr', 
41
        [
42
            'data_set[date]' => '2019-04-11',
43
            'data_set[time]' => '0',
44
            'data_set[type]' => 'JIS'
45
        ]);
46
        $this->assertTrue($client->getResponse()->isSuccessful());
47
    }
48

  
49
    public function testFormSubmitInvalid() {
50
        $client = static::createClient();
51
        $client->request('GET', '/heatmap');
52

  
53
        $crawler = $client->submitForm('Potvrdit výběr', 
54
        [
55
            'data_set[date]' => '11-04-2019',
56
            'data_set[time]' => '0',
57
            'data_set[type]' => 'JIS'
58
        ]);
59
        $this->assertTrue($client->getResponse()->isSuccessful());
60
    }
61

  
62
    public function testOpenDataAjax() {
63
        $client = static::createClient();
64
        $client->xmlHttpRequest('POST', '/heatmap/opendata', [
65
            'name' => 'KOLOBEZKY',
66
            'date' => '2019-04-11',
67
            'time' => '9'
68
        ]);
69
        $this->assertTrue($client->getResponse()->isSuccessful());
70
    }
71

  
72
    public function testAvailableDatasetsAjax() {
73
        $client = static::createClient();
74
        $client->xmlHttpRequest('POST', '/heatmap/available', 
75
        [
76
            'date' => '2019-04-11'
77
        ]);
78
        $this->assertTrue($client->getResponse()->isSuccessful());
79
    }
80

  
81
    public function testDatesWithAvailableDatasetsAjax() {
82
        $client = static::createClient();
83
        $client->xmlHttpRequest('POST', '/heatmap/dates');
84
        $this->assertTrue($client->getResponse()->isSuccessful());
85
    }
86

  
87
    public function testDataSourcePoistionsAjax() {
88
        $client = static::createClient();
89
        $client->xmlHttpRequest('POST', '/heatmap/positions', 
90
        [
91
            'name' => 'KOLOBEZKY'
92
        ]);
93
        $this->assertTrue($client->getResponse()->isSuccessful());
94
    }
95

  
96
    public function testLastAvailableCollectionsAjax() {
97
        $client = static::createClient();
98
        $client->xmlHttpRequest('POST', '/heatmap/last');
99
        $this->assertTrue($client->getResponse()->isSuccessful());
100
    }
101

  
14 102
}
website/tests/Controller/HomeControllerTest.php
5 5
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6 6

  
7 7
class HomeControllerTest extends WebTestCase {
8

  
9 8
    public function testMainPage() {
10 9
        $client = static::createClient();
11 10
        $client->request('GET', '/');
12
        $this->assertEquals(200, $client->getResponse()->getStatusCode());
11
        $this->assertTrue($client->getResponse()->isSuccessful());
13 12
    }
14
}
13

  
14
    // public function provideLinks() {
15
    //     return [
16
    //         ['Logo Západočeské univerzity v Plzni'],
17
    //         ['Heatmap.ZČU'],
18
    //         ['Život na ZČU během dne'],
19
    //         ['Hledání anomálií'],
20
    //         ['O projektu'],
21
    //         ['Zobrazit heatmapu'],
22
    //         ['Vyzkoušet heatmapu'],
23
    //     ];
24
    // }
25

  
26
    // /**
27
    //  * @dataProvider provideLinks
28
    //  */
29
    // public function testLinks($link) {
30
    //     $client = static::createClient();
31
    //     $crawler = $client->request('GET', '/');
32
    //     $client->clickLink($link);
33
    //     $this->assertTrue($client->getResponse()->isSuccessful());
34
    // }
35
}
website/tests/Repository/OpenDataManagerTest.php
6 6
use App\Repository\OpenDataManager;
7 7

  
8 8
class OpenDataManagerTest extends KernelTestCase {
9

  
10 9
    private $manager;
11 10

  
12
    protected function setUp() : void {
13
       $kernel = self::bootKernel();
14
       $this->manager = $kernel->getContainer()->get('App\Repository\IOpenDataManager');
11
    protected function setUp(): void {
12
        $kernel = self::bootKernel();
13
        $this->manager = $kernel->getContainer()->get('App\Repository\IOpenDataManager');
14
    }
15

  
16
    public function testGetCollectionDataByName() {
17
        $this->assertFalse(empty($this->manager->getCollectionDataByName('KOLOBEZKY', '2019-04-11', '9')));
18
        $this->assertTrue(array_key_exists('number', $this->manager->getCollectionDataByName('KOLOBEZKY', '2019-04-11', '9')[0]));
19
        $this->assertTrue(array_key_exists('place', $this->manager->getCollectionDataByName('KOLOBEZKY', '2019-04-11', '9')[0]));
20
        $this->assertTrue(array_key_exists('x', $this->manager->getCollectionDataByName('KOLOBEZKY', '2019-04-11', '9')[0]));
21
        $this->assertTrue(array_key_exists('y', $this->manager->getCollectionDataByName('KOLOBEZKY', '2019-04-11', '9')[0]));
22
        $this->assertTrue(array_key_exists('date', $this->manager->getCollectionDataByName('KOLOBEZKY', '2019-04-11', '9')[0]));
15 23
    }
16
    
24

  
25
    public function testGetCollectionDataByNameInvalid() {
26
        $this->assertTrue(empty($this->manager->getCollectionDataByName(null, null, null)));
27
        $this->assertTrue(empty($this->manager->getCollectionDataByName('NIC', '2019-04-11', '9')));
28
        $this->assertTrue(empty($this->manager->getCollectionDataByName('NIC', '11-04-2020', '9')));
29
        $this->assertTrue(empty($this->manager->getCollectionDataByName('NIC', '2019-04-11', '25')));
30
    }
31

  
17 32
    public function testAvailableCollections() {
18
        $this->assertCount(3, $this->manager->getAvailableCollections());
33
        $this->assertFalse(empty($this->manager->getAvailableCollections()));
34
    }
35

  
36
    public function testGetAvailableCollectionsByDay() {
37
        $this->assertFalse(empty($this->manager->getAvailableCollectionsByDay('2019-04-11')));
38
    }
39

  
40
    public function testGetAvailableCollectionsByDayInvalid() {
41
        $this->assertTrue(empty($this->manager->getAvailableCollectionsByDay(null)));
42
        $this->assertTrue(empty($this->manager->getAvailableCollectionsByDay('11-04-2020')));
43
    }
44

  
45
    public function testIsCollectionAvailable() {
46
        $this->assertTrue($this->manager->isCollectionAvailable('KOLOBEZKY', '2019-04-11'));
47
        $this->assertFalse($this->manager->isCollectionAvailable('KOLOBEZKY', '2000-04-11'));
48
    }
49

  
50
    public function testIsCollectionAvailableInvalid() {
51
        $this->assertFalse($this->manager->isCollectionAvailable(null, null));
52
        $this->assertFalse($this->manager->isCollectionAvailable('NIC', '2019-04-11'));
53
        $this->assertFalse($this->manager->isCollectionAvailable('KOLOBEZKY', '11-04-2019'));
54
    }
55

  
56
    public function testGetDatesWithAvailableCollection() {
57
        $this->assertFalse(empty($this->manager->getDatesWithAvailableCollection()));
58
        $this->assertRegExp('/^(\d{4})-(\d{2})-(\d{2})/', $this->manager->getDatesWithAvailableCollection()[0]);
59
    }
60

  
61
    public function testGetLastAvailableCollections() {
62
        $this->assertFalse(empty($this->manager->getLastAvailableCollections()));
63
        $this->assertRegExp('/^(\d{4})-(\d{2})-(\d{2})/', $this->manager->getLastAvailableCollections()['KOLOBEZKY']);
64
    }
65

  
66
    public function testGetMaxCollectionNumberAtDay() {
67
        $this->assertGreaterThan(0, $this->manager->getMaxCollectionNumberAtDay('KOLOBEZKY', '2019-04-11'));
68
    }
69

  
70
    public function testGetMaxCollectionNumberAtDayInvalid() {
71
        $this->assertEquals(0, $this->manager->getMaxCollectionNumberAtDay(null, null));
72
        $this->assertEquals(0, $this->manager->getMaxCollectionNumberAtDay('NIC', '2019-04-11'));
73
        $this->assertEquals(0, $this->manager->getMaxCollectionNumberAtDay('KOLOBEZKY', '11-04-2019'));
74
    }
75

  
76
    public function testGetDataSourcePositions() {
77
        $this->assertFalse(empty($this->manager->getDataSourcePositions('KOLOBEZKY')));
78
        $this->assertTrue(array_key_exists('x', $this->manager->getDataSourcePositions('KOLOBEZKY')[0]));
79
        $this->assertTrue(array_key_exists('y', $this->manager->getDataSourcePositions('KOLOBEZKY')[0]));
80
    }
81

  
82
    public function testGetDataSourcePositionsInvalid() {
83
        $this->assertTrue(empty($this->manager->getDataSourcePositions(null)));
84
        $this->assertTrue(empty($this->manager->getDataSourcePositions('NIC')));
19 85
    }
20
}
86
}

Také k dispozici: Unified diff