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

eiriksm / cosy-composer / 13715678822

07 Mar 2025 07:13AM UTC coverage: 86.43% (+0.2%) from 86.28%
13715678822

push

github

web-flow
Refactor individual update (#398)

* Refactor individual update

* Code style

* new.files

* Update GitCommandsTrait.php

* Update GitCommandsTrait.php

* Update PrParamsCreator.php

608 of 643 new or added lines in 14 files covered. (94.56%)

3 existing lines in 1 file now uncovered.

1777 of 2056 relevant lines covered (86.43%)

43.43 hits per line

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

79.25
/src/ComposerInstallTrait.php
1
<?php
2

3
namespace eiriksm\CosyComposer;
4

5
use eiriksm\CosyComposer\Exceptions\ComposerInstallException;
6
use eiriksm\CosyComposer\Providers\Bitbucket;
7
use Violinist\Config\Config;
8

9
trait ComposerInstallTrait
10
{
11
    use CommandOutputTrait;
12

13
    /**
14
     * Does a composer install.
15
     *
16
     * @throws \eiriksm\CosyComposer\Exceptions\ComposerInstallException
17
     */
18
    protected function doComposerInstall(Config $config) : void
19
    {
20
        $this->log('Running composer install');
154✔
21
        $install_command = ['composer', 'install', '--no-ansi', '-n'];
154✔
22
        if (!$config->shouldRunScripts()) {
154✔
NEW
23
            $install_command[] = '--no-scripts';
×
24
        }
25
        try {
26
            if ($code = $this->execCommand($install_command, false, 1200)) {
154✔
27
                // Other status code than 0.
28
                $this->log($this->getLastStdOut(), Message::COMMAND);
1✔
29
                $this->log($this->getLastStdErr());
1✔
30
                throw new ComposerInstallException('Composer install failed with exit code ' . $code);
154✔
31
            }
32
        } catch (ComposerInstallException $e) {
1✔
33
            throw $e;
1✔
NEW
34
        } catch (\Throwable $e) {
×
NEW
35
            $this->log($this->getLastStdOut(), Message::COMMAND);
×
NEW
36
            $this->log($this->getLastStdErr());
×
NEW
37
            throw new ComposerInstallException($e->getMessage());
×
38
        }
39

40
        $command_output = $this->getLastStdErr();
154✔
41
        if (!empty($command_output)) {
154✔
NEW
42
            $this->log($command_output, Message::COMMAND);
×
43
        }
44
        $this->log('composer install completed successfully');
154✔
45
    }
46

47
    protected function runAuthExport($hostname)
48
    {
49
        // If we have multiple auth tokens, export them all.
50
        if (!empty($this->tokens)) {
157✔
51
            foreach ($this->tokens as $token_hostname => $token) {
1✔
52
                $this->runAuthExportToken($token_hostname, $token);
1✔
53
            }
54
        }
55
        $this->runAuthExportToken($hostname, $this->userToken);
157✔
56
    }
57

58
    protected function runAuthExportToken($hostname, $token)
59
    {
60
        if (empty($token)) {
157✔
61
            return;
1✔
62
        }
63
        switch ($hostname) {
64
            case 'github.com':
157✔
65
                $this->execCommand(
151✔
66
                    ['composer', 'config', '--auth', 'github-oauth.github.com', $token],
151✔
67
                    false
151✔
68
                );
151✔
69
                break;
151✔
70

71
            case 'gitlab.com':
7✔
72
                $this->execCommand(
4✔
73
                    ['composer', 'config', '--auth', 'gitlab-oauth.gitlab.com', $token],
4✔
74
                    false
4✔
75
                );
4✔
76
                break;
4✔
77

78
            case 'bitbucket.org':
4✔
79
                if (Bitbucket::tokenIndicatesUserAppPassword($this->untouchedUserToken)) {
3✔
NEW
80
                    [$bitbucket_user, $app_password] = explode(':', $this->untouchedUserToken);
×
NEW
81
                    $this->execCommand(
×
NEW
82
                        ['composer', 'config', '--auth', 'http-basic.bitbucket.org', $bitbucket_user, $app_password],
×
NEW
83
                        false
×
NEW
84
                    );
×
85
                } else {
86
                    $this->execCommand(
3✔
87
                        ['composer', 'config', '--auth', 'http-basic.bitbucket.org', 'x-token-auth', $token],
3✔
88
                        false
3✔
89
                    );
3✔
90
                }
91
                break;
3✔
92

93
            default:
94
                $this->execCommand(
2✔
95
                    ['composer', 'config', '--auth', sprintf('gitlab-oauth.%s', $token), $hostname],
2✔
96
                    false
2✔
97
                );
2✔
98
                break;
2✔
99
        }
100
    }
101
}
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

© 2026 Coveralls, Inc