Example #1
0
    public function testCI()
    {
        $old_rev = "377d2edc1da549a80b5b44286e7dcaf59cee300a";
        $current_rev = "190fc6a9fddcae0313decbbbce92e4a83bf47ab9";
        XRef::setConfigValue('mail.reply-to', '*****@*****.**');
        XRef::setConfigValue('mail.from', '*****@*****.**');
        XRef::setConfigValue('mail.to', array('*****@*****.**', '{%ae}', '{%an}@xref-lint.net'));
        XRef::setConfigValue('project.name', 'unit-test');
        XRef::setConfigValue('project.source-url', 'https://github.com/gariev/xref/blob/{%revision}/{%fileName}#L{%lineNumber}');
        XRef::setConfigValue('xref.smarty-class', self::SMARTY_CLASS_PATH);
        XRef::setConfigValue('xref.data-dir', 'tmp');
        $scm = $this->xref->getSourceCodeManager();
        $file_provider_old = $scm->getFileProvider($old_rev);
        $file_provider_new = $scm->getFileProvider($current_rev);
        $modified_files = $scm->getListOfModifiedFiles($old_rev, $current_rev);
        $lint_engine = new XRef_LintEngine_ProjectCheck($this->xref, false);
        $errors = $lint_engine->getIncrementalReport($file_provider_old, $file_provider_new, $modified_files);
        list($recipients, $subject, $body, $headers) = $this->xref->getNotificationEmail($errors, 'tests-git', $old_rev, $current_rev);
        //print_r(array($recipients, $subject, $body, $headers));
        // assert that our comparison function works
        $this->assertTrue($this->strSmartSpaces("\t hello,\r \n world  ") == $this->strSmartSpaces("hello, world"));
        $this->assertTrue($this->strSmartSpaces("\t hello,\r \n world  ") != $this->strSmartSpaces("hello , world"));
        $this->assertTrue(count($recipients) == 3);
        $this->assertTrue($recipients[0] == '*****@*****.**');
        $this->assertTrue($recipients[1] == '*****@*****.**');
        $this->assertTrue($recipients[2] == '*****@*****.**');
        $this->assertTrue($this->strSmartSpaces($subject) == "XRef CI unit-test: tests-git/190fc6a");
        $expected_body = <<<END
            <html><body>
            Hi, you've got this e-mail as the author (gariev) of commit 190fc6a to branch tests-git.
            It looks like there are problems in file(s) modified since previous revision 377d2ed:
                <ul>
                    <li>broken.php</li>
                    <ul>
                        <li>
                            <span class='error'>error</span>
                            (<a href="https://github.com/gariev/xref/blob/master/README.md#xr010">xr010</a>): Use of unknown variable (\$error)
                             at <a href="https://github.com/gariev/xref/blob/190fc6a9fddcae0313decbbbce92e4a83bf47ab9/broken.php#L3">line 3</a>
                        </li>
                    </ul>
                </ul>
            <p>If the problems above are real, you can fix them.
            If these warnings are from code merged from other branch and not result of merge conflict, you can ignore them or find the author of the original commit.
            If the report is wrong, you can help <a href='mailto:gariev@hotmail.com?subject=xref'>improve XRef CI</a> itself and/or ignore this e-mail.
            </p>
            <p><small>
              Generated by XRef CI version <<VERSION>>. About XRef:
                <a href="https://github.com/gariev/xref/blob/master/README.md">documentation</a>,
                <a href="https://github.com/gariev/xref/">source code</a>,
                <a href="http://xref-lint.net/bin/xref-lint.php">online tool</a>.
            </small></p>
            </body></html>
END;
        $expected_body = str_replace('<<VERSION>>', XRef::version(), $expected_body);
        $this->assertTrue($this->strSmartSpaces($body) == $this->strSmartSpaces($expected_body));
        $expected_headers = <<<END
            MIME-Version: 1.0
            Content-type: text/html
            Reply-to: no-reply@xref-lint.net
            From: ci-server@xref-lint.net
END;
        $this->assertTrue($this->strSmartSpaces($headers) == $this->strSmartSpaces($expected_headers));
    }
Example #2
0
 public function testIncrementalProjectCheckOnDeletedFile()
 {
     // assert than there are no errors if both files are modified
     $lint_engine = new XRef_LintEngine_ProjectCheck($this->xref, false);
     $file_provider1 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php class A { const FOO = 1; } ', 'fileB.php' => '<?php echo A::FOO; '));
     $file_provider2 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php class A { } ', 'fileB.php' => '<?php echo "hi"; '));
     $report = $lint_engine->getIncrementalReport($file_provider1, $file_provider2, array("fileA.php", "fileB.php"));
     $this->assertTrue(count($report) == 0);
     // and no errors if one file is deleted
     $lint_engine = new XRef_LintEngine_ProjectCheck($this->xref, false);
     $file_provider1 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php class A { const FOO = 1; } ', 'fileB.php' => '<?php echo A::FOO; '));
     $file_provider2 = new XRef_FileProvider_InMemory(array('fileA.php' => '<?php class A { } '));
     $report = $lint_engine->getIncrementalReport($file_provider1, $file_provider2, array("fileA.php", "fileB.php"));
     $this->assertTrue(count($report) == 0);
 }