Skip to content

Commit 5161d7f

Browse files
authored
Added file permission tests. (#175)
1 parent e9b799e commit 5161d7f

2 files changed

Lines changed: 150 additions & 0 deletions

File tree

CLAUDE.md

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
Git Artifact is a PHP CLI tool that packages code artifacts from a source repository and pushes them to a destination repository. It's designed for deployment workflows where built artifacts need to be deployed to a separate repository.
8+
9+
## Development Commands
10+
11+
### Code Quality and Linting
12+
- `composer lint` - Run code quality checks (PHPCS, PHPStan, Rector dry-run)
13+
- `composer lint-fix` - Fix code quality issues (Rector, PHPCBF)
14+
15+
### Testing
16+
- `composer test` - Run PHPUnit tests without coverage
17+
- `composer test-coverage` - Run PHPUnit tests with coverage
18+
19+
### Building
20+
- `composer build` - Build standalone PHAR executable using Box
21+
22+
## Architecture
23+
24+
### Core Components
25+
- **ArtifactCommand** (`src/Commands/ArtifactCommand.php`) - Main CLI command that orchestrates the artifact creation process
26+
- **ArtifactGitRepository** (`src/Git/ArtifactGitRepository.php`) - Extended Git repository class with artifact-specific operations
27+
- **Traits** (`src/Traits/`) - Reusable functionality:
28+
- `TokenTrait` - Handle token replacement in branch names and commit messages
29+
- `LoggerTrait` - Logging functionality
30+
- `FilesystemTrait` - File system operations
31+
32+
### Application Entry Points
33+
- `git-artifact` - Main executable script with autoloader discovery
34+
- `src/app.php` - Application bootstrap using Symfony Console
35+
36+
### Deployment Modes
37+
The tool supports two deployment modes:
38+
1. **force-push** (default) - Pushes to same branch, overwrites destination history
39+
2. **branch** - Creates new branches in destination based on source tags
40+
41+
### Token System
42+
Supports dynamic token replacement in branch names and commit messages:
43+
- `[timestamp:FORMAT]` - Current timestamp with PHP date format
44+
- `[branch]` - Current branch name
45+
- `[safebranch]` - Branch name with non-alphanumeric chars replaced
46+
- `[tags:DELIMITER]` - Tags from latest commit
47+
48+
## Testing Structure
49+
50+
### Functional Tests (`tests/Functional/`)
51+
Integration tests that verify end-to-end functionality:
52+
- `BranchModeTest.php` - Tests branch mode deployment
53+
- `ForcePushModeTest.php` - Tests force-push mode deployment
54+
- `GeneralTest.php` - General functionality tests
55+
- `TagTest.php` - Token replacement and tagging tests
56+
57+
### Unit Tests (`tests/Unit/`)
58+
- Component-level tests for individual classes
59+
- Follow PHPUnit conventions with strict typing
60+
61+
### Test Fixtures Naming Convention
62+
- `f*` - Files with counter suffix
63+
- `i` - Ignored files
64+
- `c` - Committed files
65+
- `u` - Uncommitted files
66+
- `d` - Deleted files
67+
- `d_` - Directories
68+
- `sub_` - Sub-directories/files for wildcard testing
69+
- `f*_l` - Symlinks
70+
71+
## Code Standards
72+
73+
- Follows Drupal coding standards via PHPCS
74+
- Uses PHPStan level 9 for static analysis
75+
- Rector for automated code modernization to PHP 8.2+
76+
- PSR-4 autoloading: `DrevOps\GitArtifact\` namespace maps to `src/`
77+
78+
## Key Dependencies
79+
80+
- `symfony/console` - CLI framework
81+
- `czproject/git-php` - Git operations
82+
- `symfony/filesystem` & `symfony/finder` - File operations
83+
- `monolog/monolog` - Logging
84+
85+
## Single Test Execution
86+
87+
Run specific test classes:
88+
```bash
89+
./vendor/bin/phpunit tests/Unit/TokenTest.php
90+
./vendor/bin/phpunit tests/Functional/BranchModeTest.php
91+
```
92+
93+
Run specific test methods:
94+
```bash
95+
./vendor/bin/phpunit --filter testTokenReplacement tests/Unit/TokenTest.php
96+
```
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace DrevOps\GitArtifact\Tests\Functional;
6+
7+
use DrevOps\GitArtifact\Commands\ArtifactCommand;
8+
use DrevOps\GitArtifact\Git\ArtifactGitRepository;
9+
use PHPUnit\Framework\Attributes\CoversClass;
10+
11+
/**
12+
* Tests for file permissions preservation in artifacts.
13+
*/
14+
#[CoversClass(ArtifactCommand::class)]
15+
#[CoversClass(ArtifactGitRepository::class)]
16+
class FilePermissionsTest extends FunctionalTestBase {
17+
18+
/**
19+
* {@inheritdoc}
20+
*/
21+
protected function setUp(): void {
22+
parent::setUp();
23+
$this->mode = ArtifactCommand::MODE_FORCE_PUSH;
24+
}
25+
26+
public function testFilePermissions(): void {
27+
$permissions = [0644, 0755];
28+
$files = [];
29+
30+
foreach ($permissions as $perm) {
31+
$filename = sprintf('file_%o.txt', $perm);
32+
$file_path = $this->fixtureCreateFile($this->src, $filename, sprintf("Content with %o permissions\n", $perm));
33+
chmod($file_path, $perm);
34+
$files[$filename] = $perm;
35+
36+
$this->assertSame($perm, fileperms($file_path) & 0777);
37+
}
38+
39+
$this->gitCommitAll($this->src, 'Added files with various permissions');
40+
41+
$this->assertArtifactCommandSuccess(['--branch' => 'testbranch']);
42+
43+
$this->gitCheckout($this->dst, 'testbranch');
44+
45+
foreach ($files as $filename => $expected_perm) {
46+
$dst_file = $this->dst . DIRECTORY_SEPARATOR . $filename;
47+
$this->assertFileExists($dst_file);
48+
$actual_perm = fileperms($dst_file) & 0777;
49+
$this->assertSame($expected_perm, $actual_perm,
50+
sprintf('File %s should preserve %o permissions, got %o', $filename, $expected_perm, $actual_perm));
51+
}
52+
}
53+
54+
}

0 commit comments

Comments
 (0)