-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
170 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/Process/ChangesCount/SubversionChangesCountProcess.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\Process\ChangesCount; | ||
|
||
use Churn\File\File; | ||
use Churn\Process\ChangesCountInterface; | ||
use Churn\Process\ChurnProcess; | ||
use Symfony\Component\Process\Process; | ||
|
||
class SubversionChangesCountProcess extends ChurnProcess implements ChangesCountInterface | ||
{ | ||
|
||
/** | ||
* Class constructor. | ||
* | ||
* @param File $file The file the process is being executed on. | ||
* @param string $dateRange String containing a date range formatted for SVN. | ||
*/ | ||
public function __construct(File $file, string $dateRange) | ||
{ | ||
$process = new Process(['svn', 'log', '-q', '-r', $dateRange, $file->getFullPath()]); | ||
|
||
parent::__construct($file, $process); | ||
} | ||
|
||
/** | ||
* Returns the number of changes for a file. | ||
*/ | ||
public function countChanges(): int | ||
{ | ||
return (int) \floor(\substr_count($this->getOutput(), "\n") / 2); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Churn\Tests\EndToEnd; | ||
|
||
use Churn\Command\RunCommand; | ||
use Churn\Tests\BaseTestCase; | ||
use InvalidArgumentException; | ||
use Symfony\Component\Console\Application; | ||
use Symfony\Component\Console\Tester\CommandTester; | ||
|
||
class SubversionTest extends BaseTestCase | ||
{ | ||
/** @var CommandTester */ | ||
private $commandTester; | ||
|
||
protected function setUp() | ||
{ | ||
$application = new Application('churn-php', 'test'); | ||
$application->add(RunCommand::newInstance()); | ||
$command = $application->find('run'); | ||
$this->commandTester = new CommandTester($command); | ||
} | ||
|
||
protected function tearDown() | ||
{ | ||
$this->commandTester = null; | ||
} | ||
|
||
/** @test */ | ||
public function it_works_with_subversion() | ||
{ | ||
$exitCode = $this->commandTester->execute([ | ||
'paths' => [], | ||
'--configuration' => '/tmp/test', | ||
]); | ||
$display = $this->commandTester->getDisplay(); | ||
|
||
$expected = " | ||
___ _ _ __ __ ____ _ _ ____ _ _ ____ | ||
/ __)( )_( )( )( )( _ \( \( )___( _ \( )_( )( _ \ | ||
( (__ ) _ ( )(__)( ) / ) ((___))___/ ) _ ( )___/ | ||
\___)(_) (_)(______)(_)\_)(_)\_) (__) (_) (_)(__) | ||
+-------------------+---------------+------------+-------+ | ||
| File | Times Changed | Complexity | Score | | ||
+-------------------+---------------+------------+-------+ | ||
| /tmp/test/Foo.php | 2 | 1 | 1 | | ||
| /tmp/test/Bar.php | 1 | 1 | 0.5 | | ||
+-------------------+---------------+------------+-------+ | ||
"; | ||
|
||
$this->assertEquals(0, $exitCode); | ||
$this->assertEquals($expected, $display); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,5 +24,3 @@ RUN mkdir -p /tmp/test \ | |
&& fossil commit -m "2nd commit" | ||
|
||
COPY churn.yml /tmp/test/ | ||
|
||
CMD ["bash"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
FROM php:8.0-cli | ||
|
||
# Requirements for running phpunit | ||
RUN apt-get update && apt-get install -y git zip | ||
RUN pecl install xdebug-3.0.2 && docker-php-ext-enable xdebug | ||
ENV XDEBUG_MODE=coverage | ||
COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer | ||
|
||
# Build a subversion project | ||
RUN apt-get install -y subversion | ||
|
||
# See: https://subversion.apache.org/quick-start#setting-up-a-local-repo | ||
RUN mkdir -p $HOME/.svnrepos/ \ | ||
&& svnadmin create ~/.svnrepos/repo \ | ||
&& svn mkdir -m "Create structure." file://$HOME/.svnrepos/repo/trunk file://$HOME/.svnrepos/repo/branches file://$HOME/.svnrepos/repo/tags \ | ||
&& mkdir -p /tmp/test \ | ||
&& cd /tmp/test \ | ||
&& svn checkout file://$HOME/.svnrepos/repo/trunk ./ \ | ||
&& svn add --force ./ \ | ||
&& svn commit -m "Initial import." \ | ||
&& touch Foo.php \ | ||
&& svn add Foo.php \ | ||
&& svn commit -m "First commit" \ | ||
&& echo '<?php class Foo {}' > Foo.php \ | ||
&& echo '<?php class Bar {}' > Bar.php \ | ||
&& svn add Bar.php \ | ||
&& svn commit -m "2nd commit" | ||
|
||
COPY churn.yml /tmp/test/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
vcs: subversion | ||
directoriesToScan: | ||
- /tmp/test |