• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mlocati / nexi / 8554393244

04 Apr 2024 12:11PM UTC coverage: 4.097% (+1.1%) from 3.004%
8554393244

push

github

mlocati
Add test cards

20 of 35 new or added lines in 2 files covered. (57.14%)

71 of 1733 relevant lines covered (4.1%)

0.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.16
/src/Dictionary/TestCard.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace MLocati\Nexi\Dictionary;
6

7
use MLocati\Nexi\Dictionary\TestCard\Card;
8

9
/*
10
 * WARNING: DO NOT EDIT THIS FILE
11
 * It has been generated automaticlly from a template.
12
 * Edit the template instead.
13
 */
14

15
/**
16
 * List of cards that can be used for tests.
17
 *
18
 * @see https://developer.nexi.it/en/area-test/carte-di-pagamento
19
 */
20
class TestCard
21
{
22
    /**
23
     * @var \MLocati\Nexi\Dictionary\TestCard\Card[]
24
     */
25
    private $cards;
26

27
    public function __construct()
28
    {
29
        $this->cards = [
1✔
30
            new Card(true, 'VISA', '4349940199004549', 5, 26, '396'),
1✔
31
            new Card(true, 'MASTERCARD', '5186151650005008', 12, 26, '123'),
1✔
32
            new Card(false, 'VISA', '4349940199997007', 12, 28, '829'),
1✔
33
            new Card(false, 'MASTERCARD', '5533893874304465', 12, 28, '123'),
1✔
34
        ];
35
    }
1✔
36

37
    /**
38
     * Get the available circuits.
39
     *
40
     * @param bool|null $positiveOutcome set to true to list circuits for which we have cards with positive outcomes, false for negative outcomes, NULL for any outcome
41
     * @return string[]
42
     */
43
    public function getCircuits(?bool $positiveOutcome = null): array
44
    {
NEW
45
        $circuits = [];
×
NEW
46
        foreach ($this->cards as $card) {
×
NEW
47
            if ($positiveOutcome === null || $card->isPositiveOutcome() === $positiveOutcome) {
×
NEW
48
                $circuits[] = $card->getCircuit();
×
49
            }
50
        }
51

NEW
52
        $circuits = array_unique($circuits);
×
NEW
53
        sort($circuits, SORT_STRING);
×
54

NEW
55
        return array_values($circuits);
×
56
    }
57

58
    /**
59
     * Get sample cards.
60
     *
61
     * @param bool|null $positiveOutcome set to true for cards with positive outcomes, false for negative outcomes, NULL for any outcome
62
     * @param string $circuit set to a non empty string to retrieve cards with a specific circuit
63
     *
64
     * @return \MLocati\Nexi\Dictionary\TestCard\Card[]
65
     */
66
    public function getCards(?bool $positiveOutcome = null, string $circuit = ''): array
67
    {
68
        return array_values(array_filter(
1✔
69
            $this->cards,
1✔
70
            static function (Card $card) use ($positiveOutcome, $circuit): bool {
71
                return ($positiveOutcome === null || $positiveOutcome === $card->isPositiveOutcome()) && ($circuit === '' || $card->getCircuit() === $circuit);
1✔
72
            }
1✔
73
        ));
74
    }
75

76
    /**
77
     * Get a sample card.
78
     *
79
     * @param bool|null $positiveOutcome set to true for cards with positive outcomes, false for negative outcomes, NULL for any outcome
80
     * @param string $circuit set to a non empty string to retrieve cards with a specific circuit
81
     */
82
    public function getSampleCard(bool $positiveOutcome, string $circuit = ''): ?Card
83
    {
84
        $cards = $this->getCards($positiveOutcome, $circuit);
1✔
85

86
        return array_shift($cards);
1✔
87
    }
88
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc