11 if ( !mkdir( self::$tempDir ) ) {
12 self::$tempDir =
null;
13 throw new Exception(
'Unable to create temporary directory' );
15 mkdir( self::$tempDir .
'/gitrepo' );
16 mkdir( self::$tempDir .
'/gitrepo/1' );
17 mkdir( self::$tempDir .
'/gitrepo/2' );
18 mkdir( self::$tempDir .
'/gitrepo/3' );
19 mkdir( self::$tempDir .
'/gitrepo/1/.git' );
20 mkdir( self::$tempDir .
'/gitrepo/1/.git/refs' );
21 mkdir( self::$tempDir .
'/gitrepo/1/.git/refs/heads' );
22 file_put_contents( self::$tempDir .
'/gitrepo/1/.git/HEAD',
23 "ref: refs/heads/master\n" );
24 file_put_contents( self::$tempDir .
'/gitrepo/1/.git/refs/heads/master',
25 "0123456789012345678901234567890123abcdef\n" );
26 file_put_contents( self::$tempDir .
'/gitrepo/1/.git/packed-refs',
27 "abcdef6789012345678901234567890123456789 refs/heads/master\n" );
28 file_put_contents( self::$tempDir .
'/gitrepo/2/.git',
29 "gitdir: ../1/.git\n" );
30 file_put_contents( self::$tempDir .
'/gitrepo/3/.git',
31 'gitdir: ' . self::$tempDir .
"/gitrepo/1/.git\n" );
35 if ( self::$tempDir ) {
42 $this->
setMwGlobals(
'wgGitInfoCacheDirectory', __DIR__ .
'/../data/gitinfo' );
47 $this->assertEquals(
'refs/heads/master', $gitInfo->
getHead() );
48 $this->assertEquals(
'0123456789abcdef0123456789abcdef01234567',
52 $this->assertContains(
'0123456789abcdef0123456789abcdef01234567',
64 $dir =
$GLOBALS[
'IP'] .
'/testMissingJsonData';
67 $this->assertFalse( $fixture->cacheIsComplete() );
69 $this->assertEquals(
false, $fixture->getHead() );
70 $this->assertEquals(
false, $fixture->getHeadSHA1() );
71 $this->assertEquals(
false, $fixture->getHeadCommitDate() );
72 $this->assertEquals(
false, $fixture->getCurrentBranch() );
73 $this->assertEquals(
false, $fixture->getHeadViewUrl() );
76 $this->assertTrue( $fixture->cacheIsComplete() );
80 $dir = self::$tempDir .
'/gitrepo/1';
83 $this->assertEquals(
'refs/heads/master', $fixture->getHead() );
84 $this->assertEquals(
'0123456789012345678901234567890123abcdef', $fixture->getHeadSHA1() );
88 $dir = self::$tempDir .
'/gitrepo/2';
91 $this->assertEquals(
'refs/heads/master', $fixture->getHead() );
92 $this->assertEquals(
'0123456789012345678901234567890123abcdef', $fixture->getHeadSHA1() );
96 $dir = self::$tempDir .
'/gitrepo/3';
99 $this->assertEquals(
'refs/heads/master', $fixture->getHead() );
100 $this->assertEquals(
'0123456789012345678901234567890123abcdef', $fixture->getHeadSHA1() );
104 $dir = self::$tempDir .
'/gitrepo/1';
105 unlink( self::$tempDir .
'/gitrepo/1/.git/refs/heads/master' );
106 $fixture =
new GitInfo( $dir );
108 $this->assertEquals(
'refs/heads/master', $fixture->getHead() );
109 $this->assertEquals(
'abcdef6789012345678901234567890123456789', $fixture->getHeadSHA1() );
wfTempDir()
Tries to get the system directory for temporary files.
wfRandomString( $length=32)
Get a random string containing a number of pseudo-random hex characters.
wfRecursiveRemoveDir( $dir)
Remove a directory and all its content.
static setUpBeforeClass()
assertValidGitInfo(GitInfo $gitInfo)
static tearDownAfterClass()
getHead()
Get the HEAD of the repo (without any opening "ref: ")
getHeadCommitDate()
Get the commit date of HEAD entry of the git code repository.
cacheIsComplete()
Check to see if the current cache is fully populated.
getHeadViewUrl()
Get an URL to a web viewer link to the HEAD revision.
getHeadSHA1()
Get the SHA1 for the current HEAD of the repo.
getCurrentBranch()
Get the name of the current branch, or HEAD if not found.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php